iPhone UINavigationBar change font style for all controllers with [UINavigationBar appearance]

后端 未结 3 1897
没有蜡笔的小新
没有蜡笔的小新 2021-02-09 20:27

I\'m aware that I can individually change the font of a navigation bar as outlined in this answer: Change the navigation bar's font

Currently I\'m using a more globa

3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-09 21:19

    Above answers with updates for deprecated keys and use of NSShadow:

    NSShadow *shadow = [[NSShadow alloc] init];
    shadow.shadowColor = [UIColor blackColor];
    shadow.shadowBlurRadius = 0.0;
    shadow.shadowOffset = CGSizeMake(0.0, 2.0);
    [[UINavigationBar appearance] setTitleTextAttributes: @{
                         NSForegroundColorAttributeName : [UIColor blackColor],
                                    NSFontAttributeName : [UIFont fontWithName:@"Helvetica-Light" size:0.0f],
                                  NSShadowAttributeName : shadow
    }];
    

    Also setting the font size to 0 so it automatically resizes based on navigation bar orientation/height.

提交回复
热议问题