为什么不支持带有 Storyboard 本地化属性字符串的 UILabel?
Why is UILabel with attributed string from a Storyboard localization not supported?
我很困惑为什么在使用 Storyboard/Xib - strings localization approach 时不翻译使用属性字符串的 UILabel。我知道我可以使用代码在运行时设置它,但我想像所有其他不使用属性字符串的控件一样使用默认机制。
我发现了与我完全相同的问题,例如:, 2, 3, 4
但在所有这些问题和答案中,我都没有看到苹果官方 statement/documentation link 为什么这不起作用(为什么不应该?)。
所以,我想问为什么不支持带有 Storyboard 本地化中的属性字符串的 UILabel?
如果没有提示我还想知道:
如何使用 Storyboard 中的属性字符串本地化 UILabel?
更新
我也在apple开发者论坛创建了一个question希望得到官方的答复
苹果responded on the developer forum与
This is not currently supported in Storyboard/XIB. I would encourage you to make a request on Feedback Assistant.
并最终使用了这个 ,见下文。还是希望苹果能说明原因
- (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)];
我很困惑为什么在使用 Storyboard/Xib - strings localization approach 时不翻译使用属性字符串的 UILabel。我知道我可以使用代码在运行时设置它,但我想像所有其他不使用属性字符串的控件一样使用默认机制。
我发现了与我完全相同的问题,例如:
但在所有这些问题和答案中,我都没有看到苹果官方 statement/documentation link 为什么这不起作用(为什么不应该?)。
所以,我想问为什么不支持带有 Storyboard 本地化中的属性字符串的 UILabel?
如果没有提示我还想知道:
如何使用 Storyboard 中的属性字符串本地化 UILabel?
更新
我也在apple开发者论坛创建了一个question希望得到官方的答复
苹果responded on the developer forum与
This is not currently supported in Storyboard/XIB. I would encourage you to make a request on Feedback Assistant.
并最终使用了这个
- (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)];