Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the title of a Navigation Bar programmatically?

I have a Navigation Bar in a view, and I want to change its Navigation Item title programmatically.

How is this done?

like image 554
Doug Null Avatar asked May 27 '11 15:05

Doug Null


People also ask

How do you add a title to the navigation bar?

title = @"title"; But If you have a standalone navigation bar that is created programmatically within an object of UIViewController, You have to set the initial appearance of the navigation bar by creating the appropriate UINavigationItem objects and adding them to the navigation bar object stack i.e.

How do I change the navigation bar title color in SwiftUI?

To change a navigation bar color in SwiftUI, you apply toolbarBackground modifier to the content view of NavigationStack . NavigationView is deprecated in iOS 16. toolbarBackground accepts two parameters. ShapeStyle : The style to display as the background of the bar.

How do I create a custom navigation bar in Swift?

Start with Navigation ControllerCreate a single view application in Xcode. Add two view controller into your storyboard. Create two different swift files for those view controllers and set identifiers for them. Take a button in each view controller, set constrain for them and customize as you want.


2 Answers

In your UIViewController

self.navigationItem.title = @"The title"; 
like image 196
arclight Avatar answered Oct 17 '22 22:10

arclight


Swift 3 Version:

If you use a navigation bar without navigation controller, then you can try this:

navigationBar.topItem?.title = "Your Title" 

Hope for help.

like image 27
Jerome Avatar answered Oct 17 '22 21:10

Jerome