在iOS 8中无法将搜索栏色调颜色更改为透明 [英] Can't change search bar tint color to be transparent in iOS 8

查看:143
本文介绍了在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:


对于在UIKit和其他系统框架中声明的复杂视图,视图的任何
子视图通常被视为私有并且随时可以更改
。因此,您不应尝试检索或
修改这些类型的系统提供的视图的子视图。如果这样做,
您的代码可能会在将来的系统更新期间中断。

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 8中无法将搜索栏色调颜色更改为透明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆