Nick89
Nick89

Reputation: 2998

Changing the Navigation Bar in Swift

I would simply like to know how to make my navigation bar look like the one on the left in the image below:

My current app is the one on the right

My app uses a navigation controller, and the navigation bar by default looks like the screen on the right in the image. I don't like it being so small and would like it higher and also to be able to change the colour and the font of the text used for the header.

I would appreciate any help in how to do this and where to place the code.

thanks

Upvotes: 1

Views: 2231

Answers (2)

chrisamanse
chrisamanse

Reputation: 4319

You can change the navigation bar in Interface Builder.

You can change the background color by changing the bar tint. You can also change the title font, color, and etc., as you can see below:

enter image description here

Upvotes: 4

Icaro
Icaro

Reputation: 14845

There are many ways to costumize your navigation bar:

//You can change the bar style
navigationController?.navigationBar.barStyle = UIBarStyle.Black

// You can change the background color 
navigationController?.navigationBar.barTintColor = UIColor(red: 4 / 255, green: 47 / 255, blue: 66 / 255, alpha: 1)

// You can add a logo on it
let navBarImageView = UIImageView(frame: CGRect(x: 0, y: 0, width: 30, height: 30))
navBarImageView.contentMode = .ScaleAspectFit
let navBarImage = UIImage(named: "myNavBarLogo.png")
navBarImageView.image = navBarImage
navigationItem.titleView = navBarImageView

//You can change the text color
 navigationController?.navigationBar.tintColor = UIColor.yellowColor()

//You can change the font
if let font = UIFont(name: "AppleSDGothicNeo-Thin", size: 34) {
    UINavigationBar.appearance().titleTextAttributes = [NSFontAttributeName: font]
}

You just need to play with those attributs to get the Navigation Bar as you want.

I hope that helps you!

Upvotes: 4

Related Questions