Question mark when tapping or holding font icons

129 Views Asked by At

So I recently started some tinkering with my app to get it iOS 11 compatible. Thankfully most of it seems to be.

However I did notice, that in my toolbar if I tap or tap and hold an icon, which is supplied by a ttf file from fontello, I get a question mark box.

Example of icon:

    menu = [[UIBarButtonItem alloc] initWithTitle:@"\ue811" style:UIBarButtonItemStylePlain target:self action:@selector(openMenu:)];
    [menu setTitleTextAttributes:@{NSFontAttributeName:
                                       [UIFont fontWithName:@"fontello"
                                                       size:23],
                                   NSForegroundColorAttributeName:[[UIColor alloc] initWithWhite:1.f alpha:1.f]}
                        forState:UIControlStateNormal];

It works fine in the 10.3.1 simulator. Just iOS 11 seems to be goofed up. I've read about the fixes for devices, which means to update the OS, but the simulator is running 11.2, so in theory it should be fixed.

Is anybody else having this issue? Know of a fix?

2

There are 2 best solutions below

1
On

Just add title text attributes for UIControlStateSelected also:

[menu setTitleTextAttributes:@{NSFontAttributeName:
                                  [UIFont fontWithName:@"fontello"
                                                  size:23],
                              NSForegroundColorAttributeName:[UIColor greenColor]}

forState:UIControlStateSelected];

0
On

As mentioned in the comment, iOS 11 requires you to have a setting for normal state and selected/highlighted state. Below is what is working for me. Not ideal to have extra code depending on many buttons you have, but oh well.

    [menu setTitleTextAttributes:@{NSFontAttributeName:[UIFont fontWithName:@"fontello"size:23],
                                   NSForegroundColorAttributeName:[[UIColor alloc] initWithWhite:0.f alpha:1.f]}
                        forState:UIControlStateNormal];
    [menu setTitleTextAttributes:@{NSFontAttributeName:[UIFont fontWithName:@"fontello"size:23],
                                   NSForegroundColorAttributeName:[[UIColor alloc] initWithWhite:0.f alpha:0.5f]}
                        forState:UIControlStateHighlighted];