iOS 8 Swift Xcode 6 - Set top nav bar bg color and height

前端 未结 3 1777
借酒劲吻你
借酒劲吻你 2021-02-02 03:20

I have looked everywhere and tested all the code snippets posted on Stack, but nothing works for me as I need it to work.

I simply want to set:

  • Nav bar hei
3条回答
  •  余生分开走
    2021-02-02 04:03

    Nav bar height:

    In a custom navigation controller subclass...

    The trick with this one is to NOT change the actual height of the navigation bar and instead adjust its origin.

    func viewDidLoad() {
        super.viewDidLoad()
    
        navigationBar.frame.origin.y = -10 
    }
    

    Nav bar bg color in RGB:

    In a custom navigation controller subclass...

    func viewDidLoad() {
        super.viewDidLoad()
    
        navigationBar.barTintColor = // YOUR COLOR
    }
    

    or use the appearance proxy

    UINavigationBar.appearance().barTintColor = // YOUR COLOR
    

    Nav bar centered logo

    In a custom view controller...

    func viewDidLoad() {
        super.viewDidLoad()
    
        navigationItem.titleView = UIImageView(image: // YOUR LOGO)
    }
    

提交回复
热议问题