iOS 在一個UILabel上顯示不同顏色
阿新 • • 發佈:2019-01-29
self.addressLabel = [[UILabelalloc]initWithFrame:CGRectZero];
self.addressLabel.textColor = [UIColorblackColor];
self.addressLabel.font = [UIFontsystemFontOfSize:15];
[self.contentViewaddSubview:self.addressLabel];
NSMutableAttributedString *noteStr = [[NSMutableAttributedStringalloc]initWithString
NSRange redRangeTwo = NSMakeRange([[noteStr string] rangeOfString:@"[預設地址]"].location, [[noteStr string] rangeOfString:@"[預設地址]"].length);
[noteStr addAttribute:NSForegroundColorAttributeNamevalue:[UIColorredColor] range:redRangeTwo];
[self.addressLabelsetAttributedText:noteStr];
[self.addressLabelsizeToFit];