UILabel * label = [[UILabel alloc] initWithFrame:[UIScreen mainScreen].bounds];
label.font = [UIFont systemFontOfSize:30];
label.textAlignment = NSTextAlignmentCenter;
label.numberOfLines = 0;
NSMutableAttributedString * attributedText = [[NSMutableAttributedString alloc] initWithString:@"测试文字:\n改变文字间距\n改变文字大小\n改变文字颜色\n改变文字背景\n添加文字删除线\n添加文字下划线\n设置字体倾斜\n设置文本扁平化"];
// 改变文字间距
[attributedText setAttributes:@{NSKernAttributeName:@10} range:NSMakeRange(6, 6)];
// 改变文字大小
[attributedText setAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:30]} range:NSMakeRange(13, 6)];
// 改变文字颜色
[attributedText setAttributes:@{NSForegroundColorAttributeName :[UIColor redColor]} range:NSMakeRange(20, 6)];
// 改变文字颜色
[attributedText setAttributes:@{NSBackgroundColorAttributeName: [UIColor yellowColor] } range:NSMakeRange(27, 6)];
// 添加文字删除线 (NSUnderlineStyleSingle是个枚举,详细的自己试)
[attributedText setAttributes:@{NSStrikethroughStyleAttributeName:@(NSUnderlineStyleSingle) } range:NSMakeRange(34, 7)];
// 添加文字下划线 (NSUnderlineStyleSingle是个枚举,详细的自己试)
[attributedText setAttributes:@{NSUnderlineStyleAttributeName:@(NSUnderlineStyleThick) } range:NSMakeRange(42, 7)];
// 设置字体倾斜
[attributedText setAttributes:@{NSObliquenessAttributeName:@0.5} range:NSMakeRange(50, 6)];
// 设置文本扁平化
[attributedText setAttributes:@{NSExpansionAttributeName:@0.4} range:NSMakeRange(57, 7)];
// 更改后的文字赋值
label.attributedText = attributedText;
[self.view addSubview:label];
20161103113750775.png
转载:https://blog.csdn.net/csdn8769487/article/details/53019940
网友评论