Lable modify the specified text color and size

UILabel * countentLable = [[UILabel alloc]initWithFrame:CGRectMake(100, 100, 100, 20)];

countentLable.font = [UIFont systemFontOfSize:10];

NSString * CommentStr = @ "10 House reply (23)";

NSMutableAttributedString * attributeStr = [[NSMutableAttributedStringalloc]initWithString:CommentStr];

NSRange colorFondRange = NSMakeRange([[contentStr string] rangeOfString:@"(23条)"].location, [[attributeStr string] rangeOfString@"(23条)"].length);

// [CommentStr addAttribute: NSForegroundColorAttributeName value: [UIColor redColor] range: colorFondRange]; if you just change the color with this

// [CommentStr addAttribute: NSFontAttributeName value: [UIFont systemFontOfSize: 25] range: colorFondRange]; if you only use this to modify the size of the

[countentLable setAttributedText:CommentStr];

[self.view addSubview:countentLable];

Guess you like

Origin www.cnblogs.com/FZP5/p/12497911.html
Recommended