![](/img/trans.png)
[英]NSAttributedString ignores Autoshrink and numberOfLines for UILabel (iOS 6)
[英]UILabel with NSAttributedString does work in iOS 7 but doesn't in iOS 6
我的故事板上有一個帶有以下設置的UILabel:
在我的代碼中,我使用UILabel的setText:
消息為標簽設置了相應的文本。 這在iOS 7中效果很好。
但是,在iOS 6設備或模擬器上啟動應用程序時,將完全忽略UILabel的設置:
如果我在Code中設置UILabel的attributedText屬性,則此方法有些奏效,但是我真的不想以編程方式設置我已在Storyboard中設置並在iOS 7中使用的所有標簽的樣式。
有什么建議嗎?
謝謝
更新:
同時我發現,我在情節提要中設置的attributedText-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)}";
}
如您所見,我在情節提要中選擇的字體與iOS 6中UILabel的attributedText分配的字體不同,但在iOS 7中卻沒有。
更新2:
我創建了一個示例應用程序,請在此處下載: 示例應用程序
使用此應用程序,您可以完美地重現該問題。 首先在iOS 7和iOS 6中的Simulator中運行。您將看到此處說明的結果。
您將需要使用attributedText屬性。
嘗試這個:
NSAttributedString* attrStr = [[NSAttributedString alloc]
initWithString:@"Opening Event"
attributes:[label.attributedText attributesAtIndex:0 effectiveRange:NULL]];
label.attributedText = attrStr;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.