UIBarButtonItem changes font after being pressed,

2019-06-22 07:05发布

问题:

I set up UIBarButtonItem title font through appearance proxy in AppDelegate:

[[UIBarButtonItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                      [UIFont fontWithName:@"Segoe Print" size: 14.0], UITextAttributeFont,
                                                      DEF_TITLE_COLOR,UITextAttributeTextColor,
                                                      [UIColor colorWithRed:100/255 green:128/255 blue:43/255 alpha:0.4], UITextAttributeTextShadowColor,
                                                      [NSValue valueWithUIOffset:UIOffsetMake(0, 1)], UITextAttributeTextShadowOffset, nil]
                                            forState:UIControlStateNormal&UIControlStateHighlighted&UIControlStateDisabled];

And after that I am calling presentViewController:: in some place of my app. Bar button is shown with proper font and background image, which I set up in this ViewController (not through appearance):

But when I press "Join" button, standard non-customized UIAlertView is shown, and right after it appears on the screen my barButton font changes to ... standard? And color also looks like tint color. I have no Idea what I am doing wrong, tried loads of things to figure it out:

This bug appears only on iOS7.

回答1:

Well, I've figured that apperance proxy doesn't work as I expected. I copy-pasted customization method right before a place where UIBarButtonItem is initialized, and it worked as charm.



回答2:

This may work in case of iOS 7 :

In viewDidLoad method:

[self.navigationController.navigationBar setBarTintColor:[UIColor whiteColor]];

and set Font properties as well.