Update UIBarbuttonItem font when disconnected - iOS 11

Upto iOS 10, the font for disabled and enabled uibarbuttonitem remains the same, only the color is different. But after installing my application on a device that has ios 11, the font for the disabled mode is updated (the system font is displayed), while in the allowed mode it shows the correct font that I installed.

So, for the case of iOS 11, how can I set the font for disabled mode in order to maintain consistency in the application.

+6
source share
1 answer

This seems to have changed in iOS 11, at least in my case when I use the UIAppearance protocol. Not sure if this is a mistake or intentional.

I also found that I couldn’t hide the values ​​together (for example .normal|.disabled), since that meant that it would only apply the font if the control satisfies all the states.

So I finished this:

for controlState in [UIControlState.normal, UIControlState.disabled, UIControlState.focused, UIControlState.highlighted, UIControlState.selected] {
    barButton.setTitleTextAttributes([NSFontAttributeName: customFontName], for: controlState)
}

To update it everywhere using the UIAppearance protocol:

for controlState in [UIControlState.normal, UIControlState.disabled, UIControlState.focused, UIControlState.highlighted, UIControlState.selected] {
    UIBarButtonItem.appearance().setTitleTextAttributes([NSFontAttributeName: customFontName, for: controlState);
}
+7
source

All Articles