時常碼一下舟陆,也算是對工作學到的知識的一種梳理和記憶荆陆。
關(guān)于NSTextAttribute,以前一直用的是UIText,知道有天業(yè)務上需要對一段文字做不同的處理养筒,例如前面4個字符14號字體白色曾撤,后面5個字符卻是12號字體色值為@"FFFFFF";
NSMutableAttributedString *AttributedStr = [[NSMutableAttributedString alloc]initWithString: @"開售提醒 (已搶光)"];
[AttributedStr addAttribute:NSFontAttributeName
value:[UIFont boldSystemFontOfSize:14]
range:NSMakeRange(0, 4)];
[AttributedStr addAttribute:NSFontAttributeName
value:[UIFont systemFontOfSize:12]
range:NSMakeRange(5, 5)];
[AttributedStr addAttribute:NSForegroundColorAttributeName
value:[UIColor whiteColor]
range:NSMakeRange(0, 4)];
[AttributedStr addAttribute:NSForegroundColorAttributeName
value:[UIColor colorWithHexString:@"FFFFFF"]
range:NSMakeRange(5, 5)];