在iOS7.1中颜色有变化,如何更改searchBar颜色? [英] Colour changed in iOS7.1, how to change searchBar colour?
问题描述
在iOS7.0.3 - 7.0.6上,我的searchBar颜色为金色/黄色,如下所示:
On iOS7.0.3 - 7.0.6, my searchBar colour is Gold/yellow colour like this:
但在iOS 7.1上,颜色变为如下所示:
But on iOS 7.1, colour becomes like this:
我设置
searchBar.tintColor = [UIColor clearColor];
searchBar.backgroundColor = goldColor;
searchBar.tintColor = [UIColor blackColor];
我尝试了很多方法,但都失败了。任何人都可以找出iOS 7.1中的变化吗?
I've tried so many ways and all are failed. Can anyone figure out what changes in iOS 7.1?
==============我的修复========= ======
============== My fix ===============
我通过覆盖searchBar上的视图并将搜索文本作为子视图添加到此新视图来解决此问题。
I fix this problem by covering a view on searchBar and add the search text filed as subview on this new view.
我需要指出黄金状态栏是searchBar的子视图,它的框架是 CGRectMake(0,-20,320,20)
它的背景颜色是金色。
I need point out that the gold status bar is a subView of searchBar, and it's frame is CGRectMake(0, -20, 320, 20)
and it's background colour is gold.
首先,我设置了这个:
_searchBar.translucent = YES;
_searchBar.scopeBarBackgroundImage = [self imageWithColor:UWGold];
看起来像这样:
< img src =https://i.stack.imgur.com/cFq60.pngalt =在此处输入图像说明>
然后,我展开视图覆盖状态栏,我更改了视图的frame.size.height + searchBar的高度,然后使用这一行:
Then, I expand the view cover the status bar, I changed the view's frame.size.height + searchBar's height, then use this line:
UITextField *textSearchField = [_searchBar valueForKey:@"_searchField"];
获取textSearchField,然后将此textSearchField添加到封面视图。
to get the textSearchField, then add this textSearchField to the cover view.
最后,searchBar与iOS 7.0时完全相同
At last, the searchBar is exactly like when on iOS 7.0
不是一个好方法,我需要弄清楚iOS 7.1上有什么变化并使用正确的方法来实现这一点。
Not a good way, I need figure out what changes on iOS 7.1 and use a right way to implement this.
推荐答案
试试这个:
if(IOS_7)
{
self.searchBar.searchBarStyle = UISearchBarStyleMinimal;
self.searchBar.backgroundImage = [UIImage imageWithColor:[UIColor redColor] cornerRadius:5.0f];
}
希望这对您有帮助。
这篇关于在iOS7.1中颜色有变化,如何更改searchBar颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!