您的位置:首页 > 其它

label 中可以显示不同字体,不同颜色 的text

2014-05-07 21:55 399 查看


label 中可以显示不同字体,不同颜色 的text

分享类型:应用开发相关

加coreText.framework

TTTAttributedLabel *attributedLabel = [[TTTAttributedLabel alloc] initWithFrame:CGRectMake(50, 50, 300, 80)];

//attributedLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

attributedLabel.backgroundColor = [UIColor clearColor];

NSString *text = @"12345678901234567890";

attributedLabel.text = text;

[self.view addSubview:attributedLabel];

attributedLabel.textColor = [UIColor darkGrayColor];

[attributedLabel setText:text afterInheritingLabelAttributesAndConfiguringWithBlock:^(NSMutableAttributedString *mutableAttributedString){

[mutableAttributedString addAttribute:(NSString *)kCTForegroundColorAttributeName

value:(id)[UIColor blueColor].CGColor

range:NSMakeRange(0, 4)];

UIFont *boldSystemFont = [UIFont boldSystemFontOfSize:20];

CTFontRef boldFont = CTFontCreateWithName((__bridge CFStringRef)boldSystemFont.fontName, boldSystemFont.pointSize, NULL);

[mutableAttributedString addAttribute:(NSString *)kCTFontAttributeName value:(__bridge id)boldFont range:NSMakeRange(0, 10)];

return mutableAttributedString;

}];

地址 https://github.com/mattt/TTTAttributedLabel

图片:屏幕快照 2013-07-15 下午2.19.07.png



内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: