【问题标题】:How to change the color of a TabBar in Swift? Image as Background in Navigation bar?如何在 Swift 中更改 TabBar 的颜色?图像作为导航栏中的背景?
【发布时间】:2015-05-31 02:37:06
【问题描述】:

我正在尝试将 TabBar 的颜色从默认颜色更改为其他颜色?如何使用 swift 以编程方式执行此操作?另外,如何将图像指定为导航栏的背景?抱歉,如果这是一个简单的问题,我是编程新手。

【问题讨论】:

    标签: ios swift


    【解决方案1】:

    假设您有一个标签栏控制器。 你可以在 viewDidLoad() 中做这样的事情

    self.tabBarController?.tabBar.backgroundColor = UIColor.redColor()
    self.tabBarController?.tabBar.tintColor = UIColor.blueColor()
    

    对于导航控制器图像

      var image = UIImage(named: "filename")
      self.navigationController?.navigationBar.setBackgroundImage(image, forBarMetrics: UIBarMetrics.Default)
    

    【讨论】:

    • 我试过这个,我把它放在 viewDidLoad 中,但它不适用于该页面(标签栏仍然是相同的默认颜色)但在切换到其他标签时它可以工作,我该如何解决这个问题?感谢您的回复!
    • self.tabBarController 怎么样?.tabBar.barTintColor = UIColor.blueColor()
    • 太棒了!你能检查接受答案按钮吗,不胜感激!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-09-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多