dyqrfa
Last Updated: June 21, 2019
·
241.4K
· itseranga

Customize navigation bar appearance with swift

Change navigation bar color

  • In order to change color of navigation bar for all view controllers, you have to set it in AppDelegate.swift file

  • Add following code to didFinishLaunchingWithOptions function in AppDelegate.swift

var navigationBarAppearace = UINavigationBar.appearance()

navigationBarAppearace.tintColor = uicolorFromHex(0xffffff)
navigationBarAppearace.barTintColor = uicolorFromHex(0x034517)
  • In here tintColor attribute change the background color of the navigation bar

  • barTintColor attribute affect to the color of the

  1. back indicator image
  2. button titles
  3. button images
  • This code not affect to the color of navigation bar title. It still remains on black color

Picture

Picture

Change color of navigation bar title

  • Add following code to didFinishLaunchingWithOptions function in AppDelegate.swift
var navigationBarAppearace = UINavigationBar.appearance()

navigationBarAppearace.tintColor = uicolorFromHex(0xffffff)
navigationBarAppearace.barTintColor = uicolorFromHex(0x034517)

// change navigation item title color
navigationBarAppearace.titleTextAttributes =[NSForegroundColorAttributeName:UIColor.whiteColor()]
  • titleTextAttributes affect to the title text, in here I'm setting the title text color white

Picture

Programatically change navigation bar title

  • In order to change title of the navigation item(in ViewController) you have to set the title in viewDidLoad function of ViewController
override func viewDidLoad() {
    super.viewDidLoad()

    self.navigationItem.title = "New title"
}
  • Following is an example output after this change

Picture

Change status bar color

  • In above examples status bar color is Black

  • In order to change the color of status bar we have do two changes

  • First define the property of view controller-based status bar property in your info.plist file(In setting it to NO)

Picture

  • If you open it via vim (vim <path to project>/info.plist) you can see it contains a property call UIViewControllerBasedStatusBarAppearance with false value

Picture

  • Then define the color of status bar in didFinishLaunchingWithOptions function in AppDelegate.swift (This will affect to all view controllers in your app, since it define in AppDelegate.swift)
UIApplication.sharedApplication().statusBarStyle = UIStatusBarStyle.LightContent

Picture

Define colors in hex values

  • In above codes I have define a custom function to define the colors as hex values
func uicolorFromHex(rgbValue:UInt32)->UIColor{
    let red = CGFloat((rgbValue & 0xFF0000) >> 16)/256.0
    let green = CGFloat((rgbValue & 0xFF00) >> 8)/256.0
    let blue = CGFloat(rgbValue & 0xFF)/256.0

    return UIColor(red:red, green:green, blue:blue, alpha:1.0)
}

51 Responses
Add your response

16180

how can I set NavigationBar programmatically without StoryBoard?
I added in viewDidLoad()

self.navigationItem.title = "New Title"
but it doesn't work. :(

over 1 year ago ·
16374

@xperad: If you just added a UINavigationBar (not a UINavigationController), you'll have to use the following to set the title.

self.navigationBar.topItem.title = "New Title"

over 1 year ago ·
16375

In enums in Swift, you can just use the value without specifying the name of the enum Like so,

UIApplication.sharedApplication().statusBarStyle =.LightContent

over 1 year ago ·
17566

I'm trying to change navigation bar color but in my AppDelegate.swift, there is no function didFinishLaunchingWithOptions. It's passed in to the application function.
So where do I add the code to customize the navigation bar.

over 1 year ago ·
17800

Any idea how to align the title to the left?

over 1 year ago ·
18248

Could you provide an example with a blurred background on the navigation bar? :)

over 1 year ago ·
19504

you could just do self.title = "New Title" in the viewDidLoad

over 1 year ago ·
20822

Is there a way to remove "<" when i go to next screen.

over 1 year ago ·
22159

You're rgb division is off its not 256 but 255

over 1 year ago ·
28202

@venkatp, to hide the backButton:
navigationItem.setHidesBackButton(true, animated: false)

over 1 year ago ·
28686

You used a variable and named it navigationBarAppearace and you meant navigationBarAppearance

over 1 year ago ·
29148

download tutuapp from this site https://tutuapp-helper.com/ to install the paid apps for free on iPhone.

over 1 year ago ·
29411

barTintColor - is a color of background. Not tint color.
For example, to modify the bar background tint color for all instances of UINavigationBar:
[[UINavigationBar appearance] setBarTintColor:myNavBarBackgroundColor];

https://developer.apple.com/documentation/uikit/uiappearance

over 1 year ago ·
29675

Navigation is not displaying on the screen but it shows on developer mode. Please help me to resolve it. https://babasupport.org/email/zohomail-customer-service/994

over 1 year ago ·
30077

Nice Tactics and short keys are mentioned in this article because of navigation bar appearance controlling over swift is the best way to handle this bar https://crumbles.co/xbox-customer-service-number/

12 months ago ·
30818

Many time navigation is not display on the screen but it shows on programming mode. Everything is possible on the programming language.

https://uaetechnician.ae/web-development-services

9 months ago ·
31071

I'm trying to change navigation bar color but in my AppDelegate.swift, there is no function didFinishLaunchingWithOptions. It's passed in to the application function.
So where do I add the code to customize the navigation bar.For Toshiba Error Code 0xc0000225 related issue you can visit to the https://www.toshibasupportphonenumber.com/blog/how-to-fix-toshiba-error-code-0xc0000225-in-windows-10/ and they really helped me.

8 months ago ·
31101

Hey! great appearance of navigation bar with swift..........for any problem with HP printer in error state just take help from http://printertechsupportnumbers.com/blog/fix-hp-printer-error-state-windows-10/

7 months ago ·
31769

Thanks for sharing such amazing shortcuts. Also, to get netgear extender setup guide, visit https://wifiextassist.com/netgear-n300-wifi-range-extender-setup/

5 months ago ·
31774

Sometimes it's just a matter of turning off all Wireless, or even all networking, and then reactivating it again. With Windows, the equivalent is to disable the network device, and then re-enable it. In Windows, you may have to disable networking all together and then reactivate it.
https://www.toshibasupport365.com/blog/fix-toshiba-cooling-system-error/

5 months ago ·
31804

Visit https://mywifiext-net.support/netgear-extender-setup/ and get rid of all extender problems.

5 months ago ·
31856

barTintColor - is a color of background. Not tint color.
For example, https://showbox.bio/ to modify the bar https://tutuapp.uno/ background tint color for all instances of
https://vidmate.vet/ UINavigationBar:
[[UINavigationBar appearance] setBarTintColor:myNavBarBackgroundColor];

4 months ago ·
31889

Thank you for the timely and interesting article, you've provided some great insights for an user looking to understand that http://www.aolsupport247.com/blog/aol-error-code-421/

4 months ago ·
31926

Brother Printers frequently indicate technical hitches because of inward reasons. There are numerous reasons which can cause Brother Printer Not Recognizing New Toner Cartridge. Call us now to get a reliable solution.
https://www.brotherprintersupportnumber.com/blog/fix-brother-printer-not-recognizing-new-toner-cartridge/

4 months ago ·
31937

iOS Example dedicates to becoming one of the best online resources for iOS developers. You can find a hand-curated list of awesome iOS ecosystem full of useful Objective-C and Swift libraries and examples.
ios Example

4 months ago ·
31991

I took away a lot very good points from this post and will definitely save it in my bookmarks.
Thanks for the effort you took to elaborate on this subject so thoroughly. I look forward to
future posts.
https://www.errorcodeexpert.com/how-to-fix-netflix-error-code-m7363-1260-00000026/

4 months ago ·
31993

Very useful article for me. For more please visit http://www.gojiindia.com

4 months ago ·
32056

We fix HP problems like printer computer laptop troubleshooting, however conjointly alternative computer problems. If you wish facilitate along with your antivirus. Please decision our support line at Toll Free: 1-844-881-6626.
<a href="https://www.printerssupport247.com/hp-printer-customer-support/">HP Printer Phone Number </a>

3 months ago ·
32093

Thanks for sharing such amazing shortcuts.

3 months ago ·
32126

Yes, It's Working Customize navigation bar appearance with swift..

https://showbox.news/apk/

3 months ago ·
32152

Change status bar color
• In above examples status bar color is Black
• In order to change the color of status bar we have do two changes
• First define the property of view controller-based status bar property in your info.plist file(In setting it to NO)
https://play.google.com/store/apps/details?id=com.app.crazycrush

3 months ago ·
32278

For best tech help contact geek squad tech support

3 months ago ·
32292

Knowledgeable Information

Want to secure your Virtual Machine then must Download-VIPRE-Internet-Security

VIPRE is one of the important and well-known American Antivirus company which offers various services like PC/Mac Security, Endpoint Security(Endpoint Security - Cloud,Endpoint Security - Server), Protection Services,Identity Shield Email Security (Email Security - Cloud,Email Security - Server)Threat Intelligence (Threat Analyzer Sandbox,Threat IQ) and the most famous Firewall services. Its Firewall services are extremely used by people because of its amazing features. It allows data obtaining and makes data sending and receiving very safe. The data is loaded with junk or spam filtering, restrict annoying virus, detecting malware, etc. Contact VIPRE Customer Support Number +1-800-445-2810.

Visit Here:- https://www.antivirussupporthelpdesk.com/support-for-vipre-antivirus

3 months ago ·
32358

HMM THINK THIS THE PROBLEM https://itunes.apple.com/us/app/crazy-krush/id1454524594 IS THE BEST OPTION.

2 months ago ·
32375

Thanks for the information. To get the best protection for your device from viruses contact geek squad webroot team.

2 months ago ·
32376

Thanks for the information. To get the best tech help contact geek squad support

2 months ago ·
32412

For the very first time I came to your blog and found the information shared by you really helpful. Thanks for sharing. https://www.customerservice-directory.com/norton/

2 months ago ·
32416

Find Bellsouth Email Technical Support Number
https://www.bellsouthsupportnumber.co/

2 months ago ·
32451

Thanks for the information. To get the best tech help contact geek squad online support

2 months ago ·
32627

Couponing is easy with these top coupon sites. Most have verified coupons you can print that will save you up to 90% on groceries, clothes, jcpenney coupons
www.couponmall.net/store/jcpenney/

about 2 months ago ·
32868

Nice post and thanks for share thsi information. it really helpful for me.
https://www.avastsupporthelpnumber.com/avast-customer-service

about 1 month ago ·
33024

Thanks for the information about this Really nice Post.to know more good and intresting more topics <a href="http://extremevaporizer.info/best-pre-med-schools-in-california-usa/">best pre med schools in california</a>

28 days ago ·
33083

Get help to fix AOL Mail Login issues. If you are AOL user and facing issue while login in AOL mail, read this post to resolve your issue.
URL: https://getemailservices.com/aol-mail-login/

29 days ago ·
33093
33104

The information shared by you is really helpful for all the users. Thanks for sharing
For complete QuickBooks Assistance Visit: https://www.contact-quickbooks.com/

28 days ago ·
33269

For the very first time I came to your blog and found the information shared by you really helpful. Thanks for sharing https://www.onsiteassistances.com/netgear-router-support-number

7 days ago ·
33278

Nice blog, it so gripping and communicative post. If you are facing any type of issues related to, Brother Printer Support, then you may visit our website or call us our Brother Printer Support. thank you
https://www.printererrorsupport.com/blog/brother-printer-offline-windows-10/

7 days ago ·
33683

Universiade: Games will represent Italy as a whole says De Luca. Napoli 2019 welcomes the planet to the Summer Universiade's 60th birthday. https://livesportworld.com/category/summer-universiade/ Sitting just south of Rome, Napoli has been ready to unite the dynamism of university. The 2019 Summer Universiade, the XXX Summer Universiade (Italian: Universiadi estive 2019) will be held in Naples, Italy, between 3 and 14 July 2019. Campania Governor Vincenzo De Luca, speaking from Milan on Monday at the presentation of the opening ceremony for the 2019 Summer Universiade taking place in Naples July 3-14, said he wants the Games to be a showcase for Italy as a whole.

6 days ago ·
33750

Thanks for the awesome tutorial! I think that Swift is better and simpler than Java for Android mobile app development. <a href="https://zaven.co/">Software development</a> will not be the same from now on!</p>

5 days ago ·
33792

Thank you for sharing this article. in case, if you are unable to fix the problem. visit askprob community and follow the instructions to fix the problem.
https://www.askprob.com/forums/topic/why-i-cant-sign-into-my-aol-email-going-through-aol-email-login-problem-sin/

4 days ago ·