【问题标题】:Why do i get these white subviews in iOS 12 for _UISearchBarSearchFieldBackgroundView为什么我会在 iOS 12 中为 _UISearchBarSearchFieldBackgroundView 获得这些白色子视图
【发布时间】:2020-09-03 03:15:01
【问题描述】:

我正在尝试自定义我的搜索栏,但是我得到的这种白色掩盖了我感兴趣的背景颜色。这似乎与我的黑色导航栏样式相关联。但是,当我选择默认值时,白色会被替换为黑色。有人可以帮我弄这个吗?先感谢您!附言。我用 obj-c 写这个

【问题讨论】:

    标签: objective-c xcode searchbar ios12


    【解决方案1】:

    所以我从这里找到了这个解决方案,它可以删除 2 个子视图

    iOS 11 customise search bar in navigation bar

    【讨论】:

      【解决方案2】:

      我知道已经为时已晚,但我进行了很多搜索以解决类似的问题。所以我正在添加对我有用的解决方案。与这个问题相比,我的问题略有不同。就我而言,如果我将条形颜色添加为白色,在 iOS 13+ 中它看起来非常好,但在 iOS 12 中,_UISearchBarSearchFieldBackgroundView 看起来就像问题中的屏幕截图一样。因此,我在搜索其他人也可能在此处找到的问题时,最终会出现在此页面上。

      白色实际上是 UISearchBar 的色调。对于 iOS 12,我使用了稍微不同的颜色,我注意到它也影响了它旁边的取消按钮。所以我添加了代码来使用取消按钮的原始颜色。

      if #available(iOS 13.0, *){
              customSearchBar.tintColor = .white
          }else{
              customSearchBar.tintColor = UIColor(red: 0.46, green: 0.46, blue: 0.5, alpha: 0.12) // the color found on visual debugger
              UIBarButtonItem.appearance(whenContainedInInstancesOf: [UISearchBar.self]).setTitleTextAttributes(
                  [NSAttributedString.Key.foregroundColor : UIColor.white],for: .normal)
          }
      

      在这里您可以看到我正在使用硬编码值来设置色调颜色。我在 iOS 13+ 设备上运行代码时使用可视化调试器获得了这种颜色。

      您可以看到 iOS 12 和 ios 13+ 的外观相同

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-03-08
        • 2011-01-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-12-06
        相关资源
        最近更新 更多