Set a title for all navigation controllers and navigation

[[[UINavigationBar appearance] setTitleView:button] 

I tried to set the title as a button for the entire navigation element using the above line of code, but it does not work. How can I set the title for all navigation bars in my project by writing a little code in appdelegate?

+2
source share
5 answers

Customize the appearance of the navigation bar

it’s normal to change barStyle, tintColor and translucent properties, but you should never directly change UIView level properties such as borders, borders, alpha or hidden properties.

For more details, you can follow the apple document Link to the UINavigationBar class

Edit β†’

I solved your request

 [[UINavigationBar appearance] addSubview:yourView]; 

Other Google related request

+6
source

try this dude ...

 //put whatever object in this view..for example button that you want to put... UIView* ctrl = [[UIView alloc] initWithFrame:navController.navigationBar.bounds]; ctrl.backgroundColor = [UIColor yellowColor]; ctrl.autoresizingMask = UIViewAutoresizingFlexibleWidth; [navController.navigationBar addSubview:ctrl]; 

let me know if it works or not !!!!

Happy coding !!!

0
source

This is how you create a navigation controller in addDelegate and set a title for it, you need to add the following code to the didFinishLaunchingWithOptions method. Note that you need to set the root view for the viewController, which will be the viewController that will be displayed inside the navigationController.

  yourViewController *mainVC = [[yourViewController alloc]init]; UINavigationController *navigationController1 = [[UINavigationController alloc] initWithRootViewController:mainVC]; navigationController1.title = @"title"; [window addSubview:navigationController1.view]; 
0
source

If you are using iOS4, you can override drawRect

 @implementation UINavigationBar (UINavigationBarCategory) -(void)drawRect:(CGRect)rect { UIImageView *itleImageView = //create object [self addSubView:titleImageView]; //set title view in navigation bar } @end 

iOS 5

 if ([[UIDevice currentDevice].systemVersion floatValue] >= 5.0) { if ([self.navigationController.navigationBar respondsToSelector:@selector( setBackgroundImage:forBarMetrics:)]){ UIImageView *itleImageView = //create object [self.navigationController.navigationBar addSubView:titleImageView]; } } 

I think this is correct as I have not implemented.

0
source

I wanted to add a logo to every NavigationController, so I subclassed UINavigationController and used it in viewDidLoad -Method

 UIImage *logo =[UIImage imageNamed:@"logo"]; CGFloat navWidth = self.navigationBar.frame.size.width; CGFloat navHeight = self.navigationBar.frame.size.height; UIImageView *logoView = [[UIImageView alloc] initWithFrame:CGRectMake(navWidth-logo.size.width - 5, (navHeight - logo.size.height) / 2, logo.size.width, logo.size.height)]; logoView.image = logo; [self.navigationBar addSubview:logoView]; 
0
source

Source: https://habr.com/ru/post/1492348/


All Articles