iOS 9中的iOS UISearchBar背景色 [英] IOS UISearchBar Background Color In iOS 9

查看:66
本文介绍了iOS 9中的iOS UISearchBar背景色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经搜索了一段时间,希望我的搜索栏显示像BBC新闻应用程序

I have been search a while for this issue , I want my search bar display like BBC News App

我尝试所有相关方法

  for view in searchBar.subviews {
        if view.isKindOfClass(NSClassFromString("UISearchBarBackground")!) {
            view.removeFromSuperview()
            break;
        }
  }

    self.searchBar.tintColor = UIColor.clearColor()
    self.searchBar.backgroundColor = UIColor.clearColor()
    self.searchBar.translucent = true

这是我的输出

我想念什么吗???请帮助我,谢谢!

Am I miss something ??? Please Help me , thx !

推荐答案

Swift 3

要完全删除背景,请将backgroundImage设置为空图像:

searchBar.backgroundImage = UIImage()

要设置自定义背景色,请使用barTintcolor属性:

To set a custom background color, use barTintcolor property:

searchBar.barTintColor = .green

这篇关于iOS 9中的iOS UISearchBar背景色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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