iOS:如何用一种颜色replacesearch栏背景闪耀/发光

如何从search栏的背景中删除闪光/发光(渐变)。 我想用一种颜色来replace它。

由此:

在这里输入图像说明

像这样的东西

在这里输入图像说明

使用

searchbar.backgroundImage = //your image here 

你可以使用我为uiimage创build的漂亮的类别,它会根据颜色生成一个图片

https://github.com/Hackmodford/HMUIImage-imageWithColor

所以一起看起来就像这样

 searchBar.backgroundImage = [UIImage imageWithColor:[UIColor blueColor]]; 

这将产生你想要的效果。

1删除光面背景:

UISearchBar有UISearchBarBackground类的子视图,只需循环子视图,当你find该类的子视图时,将其alpha设置为0。

RubyMotion示例:

 searchBar.subviews.each { |v| v.alpha = 0 if v.class == UISearchBarBackground } 

2要添加纯色背景,请覆盖drawRect方法:

RubyMotion示例:

 def drawRect(rect) blackColor = '#222222'.to_color context = UIGraphicsGetCurrentContext() CGContextSetFillColor(context, CGColorGetComponents(blackColor.CGColor)) CGContextFillRect(context, rect) end 

不要以为你可以,自己尝试一下,它似乎是API的一部分,inheritance人类似的post ,要求同样的事情FB的原因是一个纯色是因为afaik FB应用程序使用Three20框架。 但是,即使所有的尺寸都缩小了,仍然是一个30英尺的大小,对于search栏来说是极端的矫枉过正

甚至不知道如果一个图像将工作,因为你不能设置栏本身周围的区域是清晰或透明的,以将图像放在它下面