ios - 使用大小类更改字体大小

标签 ios objective-c iphone storyboard adaptive-ui

我在我的storyboard 中使用size classes 来创建自适应布局,并且我在其中有attributed UILabel。现在我想更改这些标签的 iPad 字体大小,但似乎 UILabelsize 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

Change the font size

关于ios - 使用大小类更改字体大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30801045/

相关文章:

ios - Soomla 的 Apple 产品 ID

ios - 关于 iOS 项目的全局变量

iphone - 是否有记录的方法来设置 iPhone 方向?

objective-c - NSArray:删除除前 20 个元素之外的所有元素

ios - MPMusicPlayerController 不准备/预加载正确

ios - swift xcode 播放播放器列表中的声音文件

objective-c - 仅从字符列表中删除字符的第一个实例

ios - 如何在 ios 中使用 ibeacons 进行双向通信?

iphone - 动态UITableViewCell高度

iphone - 在 iPhone 中检索文本文件时出现问题