How do you use NSAttributedString?

后端 未结 15 939
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-22 04:19

Multiple colours in an NSString or NSMutableStrings are not possible. So I\'ve heard a little about the NSAttributedString which was introduced wit

15条回答
  •  既然无缘
    2020-11-22 04:49

    - (void)changeColorWithString:(UILabel *)uilabel stringToReplace:(NSString *) stringToReplace uiColor:(UIColor *) uiColor{
        NSMutableAttributedString *text =
        [[NSMutableAttributedString alloc]
         initWithAttributedString: uilabel.attributedText];
    
        [text addAttribute: NSForegroundColorAttributeName value:uiColor range:[uilabel.text rangeOfString:stringToReplace]];
    
        [uilabel setAttributedText: text];
    
    }
    

提交回复
热议问题