字體大小一樣
NSString *heightlightString = @"叫我第一名";
NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:heightlightString];
[str addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(2, 3)];
label.attributedText = str;
字體大小不一樣
NSString *string = [NSString stringWithFormat:@"聯(lián)系電話:12345678899"];
NSMutableAttributedString *myString = [[NSMutableAttributedString alloc] initWithString:string];
[myString addAttributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:20], NSForegroundColorAttributeName:[UIColor redColor]} range:NSMakeRange(5, 11)];
clockLabel.attributedText = stra;
label.attributedText = myString;
range需要location和length兩個(gè)參數(shù)贡未,設(shè)置想要改動(dòng)的字體顏色和范圍.