我在导航项的标题视图中添加了一个搜索栏。搜索功能正常工作,但使用导航控制器时,搜索栏的背景颜色会改变,如下所示。
我唯一更改颜色的地方是通过Xcode在Storyboard中更改导航项的颜色。
以下是将搜索栏放置在标题视图中的相关代码。
什么原因导致这种颜色?
尝试使用bartint更改颜色。
我唯一更改颜色的地方是通过Xcode在Storyboard中更改导航项的颜色。
以下是将搜索栏放置在标题视图中的相关代码。
_searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
[_searchController.searchBar sizeToFit];
self.navigationItem.titleView = _searchController.searchBar;
什么原因导致这种颜色?
尝试使用bartint更改颜色。
[_searchController.searchBar setBarTintColor:[UIColor clearColor]];
但我遇到了这个问题
而且还有一些不正常工作的事情。
[_searchController.searchBar setBarTintColor:self.navigationController.navigationBar.tintColor];
_searchController.searchBar.backgroundColor = self.navigationController.navigationBar.tintColor;
同时使用 backgroundColor
属性时,似乎这个颜色与设置的不一样。看这里使用 redColor
: