从 Xcode 5 升级到 6,现在我的搜索栏色调为黑色。
试图通过 Storyboard 右 Pane >“Bar Tint”将其更改为清除颜色,但它仍然是黑色。
也以编程方式尝试:
[self.searchBar setTintColor:[UIColor clearColor]];
还是黑的:(
有什么想法吗?
最佳答案
搜索栏上的 tintColor
属性与 UINavigationBar 非常相似,可更改按钮的颜色,以及更改闪烁光标的颜色,而不是实际的搜索栏背景。您要使用的是 barTintColor
属性。
searchbar.barTintColor = [UIColor orangeColor];
searchbar.tintColor = [UIColor greenColor];
产生以下丑陋但信息丰富的结果:
如果你想要一个完全透明的搜索栏,你还需要设置背景图片:
searchbar.barTintColor = [UIColor clearColor];
searchbar.backgroundImage = [UIImage new];
编辑:我强烈建议不要遍历和修改任何 UIKit 对象的 subview ,正如其他答案中所建议的那样。来自 Apple 的文档:
For complex views declared in UIKit and other system frameworks, any subviews of the view are generally considered private and subject to change at any time. Therefore, you should not attempt to retrieve or modify subviews for these types of system-supplied views. If you do, your code may break during a future system update.
https://developer.apple.com/documentation/uikit/uiview/1622614-subviews
关于ios - 无法将搜索栏色调颜色更改为在 iOS 8 中透明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26064677/