I have an app with a deployment target of iOS 9.3.
I have just upgraded to Xcode 9.0.1, and have noticed this issue across all simulator devices and my own iPhone7 device running iOS11. The issue does not impact devices running < iOS11.
I am initialising a left bar button item, with a custom font as follows (in viewDidLoad):
UIBarButtonItem *safeModeButton = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:self action:@selector(toggleSafeMode)];
[safeModeButton setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[UIFont fontWithName:@"Sosa-Regular" size:31],NSFontAttributeName,
nil]forState:UIControlStateNormal];
[self.navigationItem setLeftBarButtonItem:safeModeButton];
self.navigationItem.leftItemsSupplementBackButton = YES;
Shortly after in another method, I set the bar button title as follows:
self.navigationItem.leftBarButtonItem.title = @"è";
The problem is, I am seeing the actual è text on the button, rather then the symbol which should be rendered. è for the "Sosa-Regular" font is a symbol.
I previously didn't have this problem prior to the Xcode9/iOS11 upgrade. I have tried explicitly setting the titleTextAttributes before I set the title, but it always just shows the è. It's as if the titleTextAttributes is not persistent or setting the title outside viewDidLoad resets the titleTextAttributes for the button. If I set the title text in viewDidLoad, it's all working ok.
Any ideas would be appreciated.
Found the answer to this after playing around for a while. Shortly after initialising the
UIBarButtonItem
, I set it toenabled = false
.As I only specified the title text attributes for
UIControlStateNormal
, it was not applicable forUIControlStateDisabled
. Strange this only came up with iOS11. So adding this line fixed the problem: