iOS全局设置UINavigationBar和UIBarButtonItem的字体大小

小浣熊博客地址
一.在AppDelegate里进行设置
代码如下:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    _window.backgroundColor = [UIColor whiteColor];
    
    UINavigationBar *navigationBar = [UINavigationBar appearance];
    NSDictionary *attr = @{NSFontAttributeName: [UIFont systemFontOfSize:13]};
    [navigationBar setTitleTextAttributes:attr];
    
    UIBarButtonItem *barButtonItem = [UIBarButtonItem appearance];
    [barButtonItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:13], NSFontAttributeName, nil] forState:UIControlStateNormal];
    return YES;
}

看到网上有很多设置的文章,但是很多存在bug,例如如果不在AppDelegate进行全局设置,就会非常麻烦,并且可能出现bug
参考文档:

  1. UINavigationBar字体设置
  2. UIBarButtonItem字体设置

你可能感兴趣的:(iOS全局设置UINavigationBar和UIBarButtonItem的字体大小)