How to change the font and text color of the title of UINavigationBar

前端 未结 6 667
滥情空心
滥情空心 2021-01-07 18:05

I want to be change the font of the title to Avenir, and I want to make it white. Here is my code in the viewDidLoad method:

UINavigationBar.app         


        
6条回答
  •  离开以前
    2021-01-07 18:12

    If you want the styles to be applied through out the whole app add these lines in the AppDelegate.m file.

    NSShadow* shadow = [NSShadow new]; 
    shadow.shadowOffset = CGSizeMake(0.0f, 0.0f); 
    shadow.shadowColor = [UIColor blackColor]; 
    
    [[UINavigationBar appearance] setTitleTextAttributes: @{
    NSForegroundColorAttributeName: [UIColor whiteColor],
    NSFontAttributeName: [UIFont fontWithName:@"Kelvetica Nobis" size:20.0f],
    NSShadowAttributeName: shadow 
    }];
    

    NSForegroundColorAttributeName sets the Font color.

    NSFontAttributeName sets a custom font face to the title text.

    NSShadowAttributeName applies a nice shadow effect to the text, you can remove this part if you want.

    Also in advance, you can add these line to hide the text that comes up in back button in action bar when you navigate to another view within the navigation controller.

    [[UIBarButtonItem appearance]
         setBackButtonTitlePositionAdjustment:UIOffsetMake(-1000, -1000)
         forBarMetrics:UIBarMetricsDefault];
    

    Hope this help your question :)

提交回复
热议问题