iOS 13对UISearchBar色彩的更改,无法实现相同的结果 [英] iOS 13 Changes to UISearchBar tint's, can't achieve the same outcome

查看:73
本文介绍了iOS 13对UISearchBar色彩的更改,无法实现相同的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我整天都在尝试,试图弄清楚如何使我的UISearchBar在iOS13中显示与在iOS12/11中显示的相同

I've been experimenting all day and trying to figure out just how to get my UISearchBar to appear the same in iOS13 as it appears in iOS12/11

因此,添加搜索栏的方式只是一个新的UISearchController.

So the way the search bar is added is simply a new UISearchController.

            var searchController = new UISearchController(searchResultsController: null);
            searchController.SearchBar.Placeholder = "Search";
            searchController.SearchResultsUpdater = this;
            searchController.HidesNavigationBarDuringPresentation = false;
            searchController.DimsBackgroundDuringPresentation = false;

            NavigationItem.SearchController = searchController;
            NavigationItem.HidesSearchBarWhenScrolling = false;

iOS 11/12上的结果:

The results on iOS 11/12:

在iOS 13上的结果:

The results on iOS 13:

在iOS 13上,我正在使用新的UINavigationBarAppearance代码,如下所示:

On iOS 13 I am using the new UINavigationBarAppearance code like this:

                var appearance = new UINavigationBarAppearance();
                appearance.ConfigureWithOpaqueBackground();
                appearance.BackgroundColor = ColorPalette.TintColor;
                appearance.TitleTextAttributes = new UIStringAttributes { ForegroundColor = UIColor.White };

                NavigationItem.StandardAppearance = appearance;

在iOS 11/12上,我正在使用传统方式来实现它:

On iOS 11/12 I am using legacy way to achieve it:

                NavigationController.NavigationBar.BarStyle = UIBarStyle.Black;
                NavigationController.NavigationBar.TintColor = UIColor.White;
                NavigationController.NavigationBar.BarTintColor = ColorPalette.TintColor;
                NavigationController.NavigationBar.Translucent = false;

我已经尝试了很多方法,但是似乎无法让UISearchBar本身来着色iOS11/12如何实现它.

I've tried a number of things, but can't seem to get the UISearchBar to tint by itself how iOS11/12 achieves it.

我知道新的UISearchBar现在可以访问UITextField了,我可以配置背景色的颜色了.

I know that the new UISearchBar now has access to the UITextField and I can configure the background color's etc.

推荐答案

searchBar.setSearchFieldBackgroundImage(UIImage(), for: .normal)

上面的代码具有副作用,该副作用会删除文本字段的角半径.

The code above has a side effect which removes corner radius of the text field.

扩展名

extension UISearchBar {
  /// This solves iOS 13 issue which is a light gray overay covers the textField.
  /// - Parameter color: A color for searchField
  func setSearchFieldBackgroundColor(_ color: UIColor) {
    searchTextField.backgroundColor = color
    setSearchFieldBackgroundImage(UIImage(), for: .normal)
    // Make up the default cornerRadius changed by `setSearchFieldBackgroundImage(_:for:)`
    searchTextField.layer.cornerRadius = 10
    searchTextField.clipsToBounds = true
  }
}

这篇关于iOS 13对UISearchBar色彩的更改,无法实现相同的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆