带有NSAttributedString的UILabel可以在iOS 7中运行,但在iOS 6中不可用

 年庚瑶 发布于 2023-02-11 11:48

我有一个UILabel,我的故事板中设置了以下设置:

故事板中的UILabel设置

在我的代码中,我使用UILabel的setText:消息为标签设置了相应的文本.这在iOS 7中非常好用.iOS 7视图

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

如果我在Code中设置UILabel的attributionText属性,这有点起作用,但我真的不想以编程方式设置我已经在我的Storyboard中设置和在iOS 7中工作的所有标签.

这里有什么建议?

谢谢

更新:

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

iOS 6:

(lldb) po [cell.eventName.attributedText attributesAtIndex:0 effectiveRange:NULL]
{
    NSColor = "UIDeviceWhiteColorSpace 0 1";
    NSFont = " 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 = " 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的attributesText在iOS 6中分配的字体不同,但在iOS 7中没有.

更新2:

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

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

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有