How to set font & color of the title in UINavigationBar using iOS5 appearance API?

后端 未结 7 1320
北恋
北恋 2020-12-04 10:50

I have a multiple View Controllers and I want to set the font color of all to red.

 [[UINavigationBar appearance] setFont:[UIFont boldSystemFontOfSize:12.0]]         


        
7条回答
  •  Happy的楠姐
    2020-12-04 11:41

    For deployment targets greater than or equal to iOS 6, you should use NSShadow instead:

    NSShadow * shadow = [[NSShadow alloc] init];
    shadow.shadowColor = [UIColor lightGrayColor];
    shadow.shadowOffset = CGSizeMake(0, -2);
    
    NSDictionary * navBarTitleTextAttributes =
    @{ NSForegroundColorAttributeName : [UIColor redColor],
       NSShadowAttributeName          : shadow,
       NSFontAttributeName            : [UIFont systemFontOfSize:14] };
    
    [[UINavigationBar appearance] setTitleTextAttributes:navBarTitleTextAttributes];
    

    enter image description here

提交回复
热议问题