NSMutableAttributedString使用

NSMutableAttributedString *attriString = [[NSMutableAttributedString alloc] initWithString:@"范例范例范例范例范例范例范例范例范例范例"];


[attriString addAttribute:(NSString *)kCTForegroundColorAttributeName
value:(id)[UIColor redColor].CGColor
range:NSMakeRange(3, 4)];

NSUInteger length = [attriString length];
//添加字体目标字符串从下标0开始到字符串结尾
UIFont *baseFont = [UIFont systemFontOfSize:17.0];
[attriString addAttribute:NSFontAttributeName value:baseFont
range:NSMakeRange(0, length)];


CATextLayer *textLayer = [CATextLayer layer];
textLayer.string = attriString;
textLayer.frame = CGRectMake(47, 12, 226, 56);
[self.view.layer addSublayer:textLayer];

你可能感兴趣的:(iPhone,iOS,Objective-c)