iphone - UILabel 和 NSAttributedString 在 iOS 7 中可以工作,但在 iOS 6 中不行

标签 iphone ios6 ios7 uilabel uistoryboard

我有一个 UILabel,在 Storyboard中设置了以下设置:

UILabel settings in storyboard

在我的代码中,我使用 UILabel 的 setText: 消息设置标签的相应文本。这在 iOS 7 中工作得很好。iOS 7 view

但是,在 iOS 6 设备或模拟器上启动应用程序时,UILabel 的设置将被完全忽略:iOS 6 view

如果我在代码中设置 UILabel 的 attributeText 属性,这有点有效,但我真的不想以编程方式设置我已经在 iOS 7 中设置并在 Storyboard 中使用的所有标签的样式。

这里有什么建议吗?

谢谢

更新:

同时我发现,我在 Storyboard 中设置的 attributeText-settings 甚至没有应用于 iOS 6 中的 UILabel 对象:

iOS 6:

(lldb) po [cell.eventName.attributedText attributesAtIndex:0 effectiveRange:NULL]
{
    NSColor = "UIDeviceWhiteColorSpace 0 1";
    NSFont = "<UICFFont: 0xb189240> font-family: \".Helvetica NeueUI\"; font-weight: normal; font-style: normal; font-size: 17px";
    NSKern = 0;
    NSLigature = 0;
    NSParagraphStyle = "Alignment 0, LineSpacing 0, ParagraphSpacing 0, ParagraphSpacingBefore 0, HeadIndent 0, TailIndent 0, FirstLineHeadIndent 0, LineHeight 0/0, LineHeightMultiple 0, LineBreakMode 4, Tabs (\n    28L,\n    56L,\n    84L,\n    112L,\n    140L,\n    168L,\n    196L,\n    224L,\n    252L,\n    280L,\n    308L,\n    336L\n), DefaultTabInterval 0, Blocks (null), Lists (null), BaseWritingDirection -1, HyphenationFactor 0, TighteningFactor 0, HeaderLevel 0";
    NSShadow = "NSShadow {0, -1} color = {(null)}";
}

iOS 7:

(lldb) po [cell.eventName.attributedText attributesAtIndex:0 effectiveRange:NULL]
{
    NSColor = "UIDeviceRGBColorSpace 0 0 0 1";
    NSFont = "<UICTFont: 0xc1c3cc0> font-family: \"HelveticaNeue-Light\"; font-weight: normal; font-style: normal; font-size: 21.00pt";
    NSParagraphStyle = "Alignment 2, LineSpacing 0, ParagraphSpacing 0, ParagraphSpacingBefore 0, HeadIndent 0, TailIndent 0, FirstLineHeadIndent 0, LineHeight 0/0, LineHeightMultiple 0, LineBreakMode 4, Tabs (\n    28L,\n    56L,\n    84L,\n    112L,\n    140L,\n    168L,\n    196L,\n    224L,\n    252L,\n    280L,\n    308L,\n    336L\n), DefaultTabInterval 0, Blocks (null), Lists (null), BaseWritingDirection -1, HyphenationFactor 0, TighteningFactor 0, HeaderLevel 0";
    NSShadow = "NSShadow {0, -1} color = {(null)}";
}

如您所见,我在 Storyboard 中选择的字体与 UILabel 的 attributeText 在 iOS 6 中分配的字体不同,但在 iOS 7 中则不然。

更新2:

我创建了一个示例应用程序,请在此处下载:Example application

使用此应用程序,您可以完美地重现该问题。首先使用 iOS 7 在模拟器中运行,然后使用 iOS 6。您将看到如此处所述的结果。

最佳答案

您将需要使用 attributeText 属性。

试试这个:

NSAttributedString* attrStr = [[NSAttributedString alloc] 
    initWithString:@"Opening Event" 
        attributes:[label.attributedText attributesAtIndex:0 effectiveRange:NULL]];
label.attributedText = attrStr;

关于iphone - UILabel 和 NSAttributedString 在 iOS 7 中可以工作,但在 iOS 6 中不行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20545696/

相关文章:

ios - iOS 7.0.3 中的条形半透明消失了

iphone - 崩溃,没有错误信息

ios6 - 在 xcode 中使用信号 6 终止应用程序

iphone - 符号传递错误 :Couldn't find an identity for pass. com.xxx.xxxx

ios6 - 从 Crittercism 获得了这份崩溃报告。无法找出崩溃的原因。任何提示都会有所帮助

ios - 将 UITextField 添加到导航项的标题 View

iphone - 如何在不知道键的情况下迭代字典,同时获取键和对象?

iphone - 一个简单的 UITextView 剪辑非系统字体的文本

iphone - 使用 webview 在 iphone 应用程序中播放来自 youtube 的视频

iphone - iOS6和iOS7之间UIScreenbounds和applicationFrame的区别