iOS:如何用一种颜色替换搜索栏的背景光/发光 [英] iOS: How to replace Search Bar background shine/glow with one color
本文介绍了iOS:如何用一种颜色替换搜索栏的背景光/发光的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从搜索栏的背景中删除发光/发光(渐变).我只想用一种颜色代替它.
How do I remove the shine/glow (gradient) from the background of a Search Bar. I would like to replace it with just one color.
从此:
像这样
推荐答案
1要删除有光泽的背景,请执行以下操作:
UISearchBar具有类 UISearchBarBackground 的子视图,只需循环浏览子视图,当您找到该类的子视图时,将其alpha设置为0.
UISearchBar has a subview of class UISearchBarBackground, just cycle through the subviews and when you find a subview of that class, set its alpha to 0.
RubyMotion示例:
RubyMotion example:
searchBar.subviews.each { |v| v.alpha = 0 if v.class == UISearchBarBackground }
2要添加纯色背景,请覆盖drawRect方法:
RubyMotion示例:
RubyMotion example:
def drawRect(rect)
blackColor = '#222222'.to_color
context = UIGraphicsGetCurrentContext()
CGContextSetFillColor(context, CGColorGetComponents(blackColor.CGColor))
CGContextFillRect(context, rect)
end
这篇关于iOS:如何用一种颜色替换搜索栏的背景光/发光的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文