Change the font of a UIBarButtonItem

前端 未结 16 1107
春和景丽
春和景丽 2020-12-07 09:18

\"UIToolbar

I have a UIBarButtonItem in my UIToolbar titled

16条回答
  •  一生所求
    2020-12-07 09:42

    To do this for some UIBarButtonItems but not all I recommend the following approach.

    1. Create a UIBarButtonItem subclass. Don't add anything to it - you will only use it as a custom class in the storyboard and for its appearance proxy...
    2. In your storyboard, change the custom class for all desired UIBarButtonItems to your subclass
    3. In your AppDelegate import your UIBarButtonItem subclass and add the following line to application:didFinishLaunchingWithOptions:

    In my case I subclassed UIBarButtonItem for the sole purpose of bolding the text:

    [[BoldBarButtonItem appearance] setTitleTextAttributes:
      [NSDictionary dictionaryWithObjectsAndKeys: 
        [UIFont boldSystemFontOfSize:18.0], NSFontAttributeName,nil] 
                                                  forState:UIControlStateNormal];
    

提交回复
热议问题