本文介绍了在iOS 8中无法将搜索栏色调颜色更改为透明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从Xcode 5升级到6,现在我的搜索栏色调为黑色。

Upgraded from Xcode 5 to 6 and now my search bar tint is black.

尝试通过故事板右侧窗格>Bar Tint更改它以清除颜色,但它仍然是黑色。

Tried to change it through storyboard right pane > "Bar Tint" to clear color, but it's still black.

也以编程方式尝试:

[self.searchBar setTintColor:[UIColor clearColor]];

仍为黑色:(

任何想法?

推荐答案

搜索栏上的 tintColor 属性,很像UINavigationBar,更改按钮的颜色,以及更改闪烁光标的颜色,而不是实际的搜索栏背景。您要使用的是 barTintColor 属性。

The tintColor property on search bars, much like UINavigationBar, changes the color of the buttons, as well as changes the color of the blinking cursor, not the actual search bar background. What you want to use is the barTintColor property.

searchbar.barTintColor = [UIColor orangeColor];
searchbar.tintColor = [UIColor greenColor];

产生以下丑陋但信息丰富的结果:

Produces the following ugly, yet informative, result:

如果你想完全拥有一个透明搜索栏,您还需要设置背景图片:

If you want to have a completely transparent search bar, you need to set the background image as well:

searchbar.barTintColor = [UIColor clearColor];
searchbar.backgroundImage = [UIImage new];

编辑: 我强烈建议不要遍历和修改任何 UIKit对象的子视图,正如其他答案中所提出的那样。来自Apple的文档:

I would strongly advise against traversing and modifying the subviews of any UIKit object, as has been proposed in other answers. From Apple's documentation:

这篇关于在iOS 8中无法将搜索栏色调颜色更改为透明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-09 17:55