我在我的storyboard
中使用size classes
来创建自适应布局,并且我在其中有attributed UILabel
。现在我想更改这些标签的 iPad 字体大小,但似乎 UILabel
的 size classes
with attributed text 在 IB
中不可用.所以问题是如何更改带有属性字符串的 UILabel
的字体大小。
最佳答案
正如韦斯所说:-
你应该看看AliSoftware's OHAttributedLabel .它是绘制 NSAttributedString 的 UILabel 的子类,还提供了从 UIKit 类设置 NSAttributedString 属性的便捷方法。
来自 repo 中提供的示例:
#import "NSAttributedString+Attributes.h"
#import "OHAttributedLabel.h"
/**(1)** Build the NSAttributedString *******/
NSMutableAttributedString* attrStr = [NSMutableAttributedString attributedStringWithString:@"Hello World!"];
// for those calls we don't specify a range so it affects the whole string
[attrStr setFont:[UIFont systemFontOfSize:12]];
[attrStr setTextColor:[UIColor grayColor]];
// now we only change the color of "Hello"
[attrStr setTextColor:[UIColor redColor] range:NSMakeRange(0,5)];
/**(2)** Affect the NSAttributedString to the OHAttributedLabel *******/
myAttributedLabel.attributedText = attrStr;
// Use the "Justified" alignment
myAttributedLabel.textAlignment = UITextAlignmentJustify;
// "Hello World!" will be displayed in the label, justified, "Hello" in red and " World!" in gray.
注意:在 iOS 6+ 中,您可以使用 attributedText 呈现属性字符串UILabel 的属性。
请检查这个问题以便更好地理解:-
Iphone/Ipad Nsattributed string
编辑
您还应该检查此链接以更改字体大小。
你应该根据你的要求修改它。比如如果你不需要 dynamicaly 就不要使用 method.bumpFontSize
等
关于ios - 使用大小类更改字体大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30801045/