使用大小类更改字体大小

时间:2015-06-12 10:39:22

标签: ios objective-c iphone storyboard adaptive-ui

我在size classes中使用storyboard创建自适应布局,其中包含attributed UILabel个。现在我想要更改这些标签的iPad字体大小,但似乎size classes UILabel IB UILabel window.addEventListener('resize', function () {...}); window.addEventListener('resize', function myScroll() {...}); 。所以问题是如何使用属性字符串更改window.removeEventListener('resize', myScroll); 的字体大小。

1 个答案:

答案 0 :(得分:1)

按照韦斯的说法: -

你应该看看AliSoftware's OHAttributedLabel。它是UILabel的子类,用于绘制NSAttributedString,还提供了从UIKit类设置NSAttributedString属性的便捷方法。

来自回购中提供的样本:

#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+中,您可以使用UILabel的attributedText属性呈现属性字符串。

请检查此问题以便更好地理解: -

Iphone/Ipad Nsattributed string

修改

您还应该检查此链接以更改字体大小。 您应该根据您的要求进行修改。就像你不需要dynamicaly然后不要使用方法。bumpFontSize等。

Change the font size