3
votes

I have a UIBarButtonItem in a UINavigationBar that has some custom appearance attributes (custom font, color). It appears normally most places throughout the app.

However, when a UIAlertController with the ActionSheet style is presented over the view controller with this button, the BarButton loses its custom font appearance, leading to a strange looking "jump" on the button and an incorrect font being displayed, as can be seen here: http://giphy.com/gifs/puopiq9mPyI2Q/html5 .

I assume this is likely related to how we are setting the BarButton appearance, with the following code in AppDelegate:

NSDictionary *btnAttributes = [NSDictionary dictionaryWithObjectsAndKeys:
                                    [UIColor      whiteColor],NSForegroundColorAttributeName,
                                    [AppearanceConstants mediumFontSize20],         NSFontAttributeName,nil];
    [[UIBarButtonItem appearance] setTitleTextAttributes:btnAttributes forState:UIControlStateNormal];

My guess would be that the bar button is not in UIControlStateNormal, however it doesn't seem like theres anyway for me to tell what state the BarButton is in when the AlertController is presented, and just trying to set the title text attributes to the appropriate values for every control state didn't work either.

When I navigate to other view controllers with BarButtonItems in their NavigationBars after doing this, they still have the correct appearance and if I go back to the problematic screen afterward it will have the correct appearance, until the AlertController is presented again.

1
You can try setting self.view.tintAdjustmentMode = UIViewTintAdjustmentModeNormal in your view controller or self.window.tintAdjustmentMode = UIViewTintAdjustmentModeNormal in your app delegate. Some other posts suggested this as a solution.Dennis W.
Thanks for the suggestion, didn't seem to fix the problem. This actually isn't unique to the action sheet, I just realized. We have another view controller that presents over the view and it causes the same issue, though it is less noticeable as we blur the background so the "jump" can't be seen. The font styling is still removed, however.Alex Lipsett

1 Answers

2
votes

I reset the style after presenting the ActionSheet

UIAlertController *alertVC = ... 

[self presentViewController:alertVC animated:YES completion:^{
    [self.navigationItem.leftBarButtonItem setDefaultAppearanceForSpecificItem];
    [self.navigationItem.rightBarButtonItem setDefaultAppearanceForSpecificItem];
}];

I created a category on UIBarButtonItem to help me

[self setTitleTextAttributes:@{
        NSFontAttributeName: [UIFont systemFontOfSize:14],
        NSForegroundColorAttributeName: [UIColor VKBlueColor]
} 
forState:UIControlStateNormal];