iOS 8 Swift Xcode 6 - Set top nav bar bg color and height
ios8, navbar, swift, xcode
Solution
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)
}
Problem
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 height - Nav bar bg color in RGB - Nav bar centered logo I'm working with iOS8, Xcode 6 and Swift. Many thanks for a clear answer! This is my code in ViewController.swift ``` // Set nav bar height navigationController?.navigationBar.frame.origin.y = -10 // Set nav bar bg color var navBarColor = UIColor(red: 4 / 255, green: 47 / 255, blue: 66 / 255, alpha: 1) navigationController?.navigationBar.barTintColor = navBarColor // Set nav bar logo let navBarImageView = UIImageView(frame: CGRect(x: 0, y: 0, width: 30, height: 30)) navBarImageView.contentMode = .ScaleAspectFit let navBarImage = UIImage(named: "navBarLogo.png") navBarImageView.image = navBarImage navigationItem.titleView = navBarImageView ```