富文本(NSMutableAttributedString)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了富文本(NSMutableAttributedString)相关的知识,希望对你有一定的参考价值。
干货:
- (void)viewDidLoad {
[super viewDidLoad];
NSString * tempStr = @"貌似这个叫富文本";
NSMutableAttributedString * attStr = [self stringTurnToAttributeStringWithString:tempStr
Font:25
TextColor:[UIColor redColor]
Range:NSMakeRange(5, 3)];
UILabel * label = [[UILabel alloc] initWithFrame:self.view.bounds];
label.textAlignment = NSTextAlignmentCenter;
label.attributedText = attStr;
[self.view addSubview:label];
}
- (NSMutableAttributedString *)stringTurnToAttributeStringWithString:(NSString *)string
Font:(CGFloat)fontSize
TextColor:(UIColor *)textColor
Range:(NSRange)range{
NSMutableAttributedString * attStr = [[NSMutableAttributedString alloc] initWithString:string];
[attStr addAttributes:@{NSForegroundColorAttributeName:textColor,
NSFontAttributeName:[UIFont systemFontOfSize:fontSize]}
range:range];
return attStr;
}
以上是关于富文本(NSMutableAttributedString)的主要内容,如果未能解决你的问题,请参考以下文章