Lable modifier la couleur de texte spécifié et la taille

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

countentLable.font = [UIFont systemFontOfSize: 10];

NSString * CommentStr = @ "10 réponse Maison (23)";

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

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

// [CommentStr addAttribute: Valeur NSForegroundColorAttributeName: [UIColor redColor] Plage: colorFondRange], si vous changez juste la couleur avec ce

// [CommentStr addAttribute: Valeur NSFontAttributeName: [UIFont systemFontOfSize: 25] Plage: colorFondRange], si vous utilisez uniquement ce pour modifier la taille de la

[CountentLable setAttributedText: CommentStr];

[Self.view addSubview: countentLable];

Je suppose que tu aimes

Origine www.cnblogs.com/FZP5/p/12497911.html
conseillé
Classement