Question mark when tapping or holding font icons

╄→гoц情女王★ 提交于 2019-12-24 23:09:49

问题


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?


回答1:


Just add title text attributes for UIControlStateSelected also:

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

forState:UIControlStateSelected];




回答2:


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];


来源:https://stackoverflow.com/questions/47814043/question-mark-when-tapping-or-holding-font-icons

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!