gpt4 book ai didi

objective-c - iOS11 中 leftBarButtonItem setTitleTextAttributes 问题

转载 作者:行者123 更新时间:2023-12-03 21:00:50 25 4
gpt4 key购买 nike

我有一个部署目标为 iOS 9.3 的应用。

我刚刚升级到 Xcode 9.0.1,并且在所有模拟器设备和我自己的运行 iOS11 的 iPhone7 设备上都注意到了这个问题。该问题不会影响运行 < iOS11 的设备。

我正在初始化一个左栏按钮项目,使用自定义字体如下(在 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;

不久之后,在另一种方法中,我将栏按钮标题设置如下:

    self.navigationItem.leftBarButtonItem.title = @"è";

问题是,我在按钮上看到实际的 è 文本,而不是应该呈现的符号。 è 代表“Sosa-Regular”字体,是一个符号。

我之前在Xcode9/iOS11升级之前没有这个问题。我在设置标题之前尝试显式设置 titleTextAttributes,但它总是只显示 è。就好像 titleTextAttributes 不是持久的,或者在 viewDidLoad 之外设置标题会重置按钮的 titleTextAttributes 。如果我在 viewDidLoad 中设置标题文本,一切正常。

任何想法将不胜感激。

最佳答案

玩了一段时间后找到了答案。初始化 UIBarButtonItem 后不久,我将其设置为 enabled = false

由于我只为 UIControlStateNormal 指定了标题文本属性,因此它不适用于 UIControlStateDisabled。奇怪的是这个只出现在iOS11上。因此添加这一行解决了问题:

[safeModeButton setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[UIFont fontWithName:@"Sosa-Regular" size:31],NSFontAttributeName,
nil]forState:UIControlStateDisabled];

关于objective-c - iOS11 中 leftBarButtonItem setTitleTextAttributes 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46956799/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com