ox_*_*ox_ 28 iphone uisearchbar ios searchbar ios8
从Xcode 5升级到6,现在我的搜索栏色调为黑色.
试图通过故事板右侧窗格>"Bar Tint"更改它以清除颜色,但它仍然是黑色.
也以编程方式尝试:
[self.searchBar setTintColor:[UIColor clearColor]];
Run Code Online (Sandbox Code Playgroud)
还是黑的:(
有任何想法吗?
Mik*_*ike 67
tintColor搜索栏上的属性与UINavigationBar非常相似,可以更改按钮的颜色,也可以更改闪烁光标的颜色,而不是实际的搜索栏背景.您想要使用的是该barTintColor物业.
searchbar.barTintColor = [UIColor orangeColor];
searchbar.tintColor = [UIColor greenColor];
Run Code Online (Sandbox Code Playgroud)
产生以下丑陋但信息丰富的结果:

如果您想要一个完全透明的搜索栏,您还需要设置背景图像:
searchbar.barTintColor = [UIColor clearColor];
searchbar.backgroundImage = [UIImage new];
Run Code Online (Sandbox Code Playgroud)

编辑:我强烈建议不要遍历和修改任何 UIKit对象的子视图,正如其他答案中提出的那样.来自Apple的文档:
对于在UIKit和其他系统框架中声明的复杂视图,视图的任何子视图通常被视为私有,并且可能随时更改.因此,您不应尝试检索或修改这些类型的系统提供的视图的子视图.如果这样做,您的代码可能会在将来的系统更新期间中断.
https://developer.apple.com/documentation/uikit/uiview/1622614-subviews
我必须使用Swift 2.0以这种方式在iOS 9上进行更改:
let image = UIImage()
searchBar.setBackgroundImage(image, forBarPosition: .Any, barMetrics: .Default)
searchBar.scopeBarBackgroundImage = image
Run Code Online (Sandbox Code Playgroud)