【问题标题】:iOS: How to replace Search Bar background shine/glow with one coloriOS:如何用一种颜色替换搜索栏背景光泽/发光
【发布时间】:2011-07-14 15:56:52
【问题描述】:

如何从搜索栏的背景中移除光泽/发光(渐变)。我想只用一种颜色替换它。

从这里:

这样的事情

【问题讨论】:

  • 你试过背景图片吗?

标签: iphone objective-c ios uisearchbar searchbar


【解决方案1】:

使用

searchbar.backgroundImage = //your image here

您可以使用我为 uiimage 创建的漂亮类别,它将根据颜色生成图像

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

所以整体看起来像这样

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

这会产生你想要的效果。

【讨论】:

    【解决方案2】:

    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
    

    【讨论】:

      【解决方案3】:

      不认为你可以,我自己尝试过,它似乎是 API 的一部分,这是一个类似的post,它问同样的事情 FB 是纯色的原因是因为 afaik FB 应用程序使用 Three20 框架。但是,即使他们缩小了所有尺寸,它的大小仍然是原始的 30 兆,在您的情况下,对于搜索栏来说是极端的矫枉过正

      甚至不知道图像是否可以工作,因为您无法将条本身周围的区域设置为清晰或透明以在其下方放置图像

      【讨论】:

      • 但是facebook应用只有6MB大小?
      • 当您转换应用以上传到商店时,它会缩小很多。由于 Three20 和大量图片,我正在为一家公司开发的应用程序有数百兆,下载大约 8mbs
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-10-10
      • 1970-01-01
      • 2017-11-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-31
      相关资源
      最近更新 更多