点击或按住字体图标时的问号

时间:2017-12-14 13:02:11

标签: ios uitoolbar uifont fontello

所以我最近开始修改我的应用程序以使其兼容iOS 11。值得庆幸的是,大部分似乎都是。

但是我确实注意到,在我的工具栏中,如果我点击或点按并按住由fontello的ttf文件提供的图标,我会收到一个问号框。

图标示例:

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

它在10.3.1模拟器中工作正常。只是iOS 11似乎搞砸了。我已经阅读了有关设备的修复程序,这意味着要更新操作系统,但模拟器运行的是11.2,所以理论上应该修复它。

还有其他人有这个问题吗?知道修复吗?

2 个答案:

答案 0 :(得分:1)

只需为 UIControlStateSelected 添加标题文字属性:

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

forState:UIControlStateSelected];

答案 1 :(得分:0)

如评论中所述,iOS 11要求您具有正常状态和选定/突出显示状态的设置。以下是对我有用的东西。根据你所拥有的许多按钮,有额外的代码并不理想,但是很好。

    [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];
相关问题