Tim*_*ten 2 iphone uilabel uistoryboard ios6 ios7
我有一个UILabel,我的故事板中设置了以下设置:

在我的代码中,我使用UILabel的setText:消息为标签设置了相应的文本.这在iOS 7中非常好用.
但是,在iOS 6设备或模拟器上启动应用程序时,UILabel的设置将被完全忽略: 
如果我在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 = "<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)}";
}
Run Code Online (Sandbox Code Playgroud)
如您所见,我在Storyboard中选择的字体与UILabel的attributesText在iOS 6中分配的字体不同,但在iOS 7中没有.
更新2:
我创建了一个示例应用程序,请在此处下载:示例应用
使用此应用程序,您可以完美地重现该问题.使用第一个iOS 7,然后使用iOS 6在模拟器中运行.您将看到此处所述的结果.
您需要使用attributedText属性.
试试这个:
NSAttributedString* attrStr = [[NSAttributedString alloc]
initWithString:@"Opening Event"
attributes:[label.attributedText attributesAtIndex:0 effectiveRange:NULL]];
label.attributedText = attrStr;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6557 次 |
| 最近记录: |