IOS 改变字符串中特定字符的颜色和大小。
UILabel *lable = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 300)]; lable.text = @"其中俩字是红色,大小为17"; NSRange rangeRmb=[lable.text rangeOfString:[NSString stringWithFormat:@"红色"]]; NSMutableAttributedString *rmbStr=[[NSMutableAttributedString alloc] initWithString:lable.text attributes:nil]; if ([[[UIDevice currentDevice] systemVersion] floatValue]>=6.0) { NSDictionary *fontDic=[NSDictionary dictionaryWithObjectsAndKeys:[UIColor redColor],NSForegroundColorAttributeName,[UIFont systemFontOfSize:17],NSFontAttributeName, nil]; [rmbStr addAttributes:fontDic range:rangeRmb]; lable.attributedText = rmbStr; }else{ lable.text=rmbStr.string; }