我特别想找一个iOS-7的答案。如果我有一张图片,答案将是
[mySearchBar setSearchFieldBackgroundImage:myImage forState:UIControlStateNormal];但我只想应用一种颜色。有没有一种简单的方法,只用一种颜色就可以做到这一点?同样,对于iOS-7。
注意:我在SO上看到了一堆非常复杂的答案:遍历,等等。我希望有一些简单的东西,不会导致我的应用程序被拒绝。
发布于 2014-07-31 06:31:08
如果我理解正确的话,您正在寻找barTintColor属性。您可以这样设置barTintColor属性,
mySearchBar.barTintColor = [UIColor blackColor];或
[mySearchBar setBarTintColor:[UIColor blackColor];希望这能有所帮助!
发布于 2014-07-31 11:30:22
首先,您需要在搜索栏中找到UITextField,然后更改其颜色。下面是获取文本字段的代码:
for (UIView *subView in searchBar.subviews)
{
for (UIView *secondLevelSubview in subView.subviews){
if ([secondLevelSubview isKindOfClass:[UITextField class]])
{
UITextField *searchBarTextField = (UITextField *)secondLevelSubview;
return searchBarTextField;
}
}
}
return nil;https://stackoverflow.com/questions/25047803
复制相似问题