NSStringstring = @"模板參數【“XX點”中的時間只能輸入大寫的輸入,如要填寫11:30,則只能輸入“十一點三十分”,其余參數輸入內容不限】";
NSRange range = [string rangeOfString: @""];
NSMutableAttributedStringattribute = [[NSMutableAttributedString alloc] initWithString: string];
[attribute addAttributes: @{NSForegroundColorAttributeName: [UIColor redColor]}range: range];
[attribute addAttributes: @{NSForegroundColorAttributeName: [UIColor blackColor]}range: NSMakeRange(0, range.location)];
[attribute addAttributes: @{NSForegroundColorAttributeName: [UIColor redColor]}range: NSMakeRange(range.location+ range.length, 55)];
[self.modelLabel setText: string];
[self.modelLabel setAttributedText: attribute];
![Upload 796CEFE7-1240-45AB-8978-7FB3B11BA506.png failed. Please try again.]
這樣就可以完成了,當然也可以一個label顯示多個不同顏色的字體。