简体   繁体   中英

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 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

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!

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:

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM