【问题标题】:Why is UILabel with attributed string from a Storyboard localization not supported?为什么不支持带有来自 Storyboard 本地化的属性字符串的 UILabel?
【发布时间】:2020-09-25 10:41:43
【问题描述】:

我很困惑为什么在使用 Storyboard/Xib - strings localization approach 时不翻译使用属性字符串的 UILabel。我知道我可以使用代码在运行时设置它,但我想使用默认机制,就像所有其他不使用属性字符串的控件一样。

我发现了与我完全相同的问题类似的问题:1234

但在这些问题和答案中,我没有看到任何官方 Apple 声明/文档链接,为什么这不应该起作用(为什么不应该呢?)。

所以,我问为什么不支持带有来自 Storyboard 本地化的属性字符串的 UILabel?

如果没有提示我还想知道:

如何使用 Storyboard 中的属性字符串本地化 UILabel?

更新

我还在苹果开发者论坛创建了question,希望得到官方的答复。

【问题讨论】:

    标签: ios localization


    【解决方案1】:

    Apple responded on the developer forum

    Storyboard/XIB 目前不支持此功能。我鼓励您在Feedback Assistant 上提出请求。

    最终使用了这个approach,见下文。我仍然希望 Apple 补充这背后的原因。

    - (void)localizeAttributedLabel:(UILabel*)label withText:(NSString*)text
    {
      NSMutableAttributedString* attributedString = [[NSMutableAttributedString alloc] initWithAttributedString:label.attributedText];
      [attributedString.mutableString setString:text];
      label.attributedText = attributedString;
    }
    
    [self localizeAttributedLabel:myLabel withText:NSLocalizedString(@"MyLabelTextKey", nil)];
    

    【讨论】:

      猜你喜欢
      • 2013-05-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-29
      • 2010-12-12
      • 2020-06-19
      • 1970-01-01
      相关资源
      最近更新 更多