【发布时间】:2011-07-14 15:56:52
【问题描述】:
如何从搜索栏的背景中移除光泽/发光(渐变)。我想只用一种颜色替换它。
从这里:
这样的事情
【问题讨论】:
-
你试过背景图片吗?
标签: iphone objective-c ios uisearchbar searchbar
如何从搜索栏的背景中移除光泽/发光(渐变)。我想只用一种颜色替换它。
从这里:
这样的事情
【问题讨论】:
标签: iphone objective-c ios uisearchbar searchbar
使用
searchbar.backgroundImage = //your image here
您可以使用我为 uiimage 创建的漂亮类别,它将根据颜色生成图像
https://github.com/Hackmodford/HMUIImage-imageWithColor
所以整体看起来像这样
searchBar.backgroundImage = [UIImage imageWithColor:[UIColor blueColor]];
这会产生你想要的效果。
【讨论】:
1 去除光泽背景:
UISearchBar 有一个 UISearchBarBackground 类的子视图,只需循环浏览子视图,当您找到该类的子视图时,将其 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 的一部分,这是一个类似的post,它问同样的事情 FB 是纯色的原因是因为 afaik FB 应用程序使用 Three20 框架。但是,即使他们缩小了所有尺寸,它的大小仍然是原始的 30 兆,在您的情况下,对于搜索栏来说是极端的矫枉过正
甚至不知道图像是否可以工作,因为您无法将条本身周围的区域设置为清晰或透明以在其下方放置图像
【讨论】: