Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setting Title for navigation bar in xcode

I have created a navigation controller programmatically,

        //Creating AddViewController Object
        addViewController *addView = [[addViewController alloc]init];
        UINavigationController *addViewControl = [[UINavigationController alloc]init];

        [addViewControl.view addSubview:addView.view];

        [self presentModalViewController:addViewControl animated:YES];

But when i add self.title = @"Title" in addViewController class. it is not displaying.

i tried with the following,

self.navigationItem.title = @"Title";

self.navigationController.navigationBar.topItem.title = @"Title";

But it's not displaying Title.

I think it is possible to do with setting a label. but the above one is direct method.

Any Idea..

like image 655
Anish Avatar asked Apr 12 '12 13:04

Anish


People also ask

How do I add a title to my navigation bar?

Use navigationBarTitle(_:) to set the title of the navigation bar. This modifier only takes effect when this view is inside of and visible within a NavigationView .

How do I customize the navigation bar title in SwiftUI?

To customize a navigation bar title view in SwiftUI, we simply set ToolbarItem of placement type . principal to a new . toolbar modifier.

How do I customize the navigation bar in Swift?

Go to the ViewController. swift file and add the ViewDidAppear method. a nav helper variable which saves typing. the Navigation Bar Style is set to black and the tint color is set to yellow, this will change the bar button items to yellow.


2 Answers

You should assign the title to the addView like addView.title = @"Title";

Another way to do it is self.navigationItem.title = @"Title";

like image 161
o15a3d4l11s2 Avatar answered Sep 30 '22 16:09

o15a3d4l11s2


In the viewController class: [self setTitle:@"title"]; or self.title=@"title";

like image 36
Marouene Tekaya Avatar answered Sep 30 '22 16:09

Marouene Tekaya