简体   繁体   English

归因于UILabel不尊重IB

[英]Attributed UILabel does not respect IB

For the first time i decided to use NSAttributed string for my UILabel, 我第一次决定对UILabel使用NSAttributed字符串,

nevertheless when i set my UILabel attributes (font, color, alignement) of my labels in IB (interface builder interface) when i run my code the attributes are never respected ! 但是,当我运行代码时,当在IB(界面构建器界面)中设置标签的UILabel属性(字体,颜色,对齐方式)时,就永远不会尊重这些属性! I have to manually add attributes to my labels : 我必须手动将属性添加到标签:

_myLabel.font = [UIFont fontWithName:@"Arial-BoldMT" size:25];

Can someone help me ? 有人能帮我吗 ?

What you're doing is applying a font font the text property of the label. 您正在做的是在标签的文本属性中应用字体。 If you'd like to assign a font for attributed text, you have to assign that font as one of the attributed string's attributes. 如果要为属性文本分配字体,则必须将该字体分配为属性字符串的属性之一。

NSString *inputString = @"fsdfdsf";

NSDictionary *attributes = @{NSFontAttributeName: [UIFont fontWithName:@"Arial-BoldMT" size:25]};

NSAttributedString *attributecString = [[NSAttributedString alloc] initWithString:inputString attributes:attributes];

[_myLabel setAttributedText:attributecString];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM