标签:style color 使用 os io for line rgb
第一步:NSMutableAttributedString与NSString关联
NSString *pingguString = [NSStringstringWithFormat:@"%@%@",pingguString1,pingguString2];
NSMutableAttributedString *str = [[NSMutableAttributedStringalloc] initWithString:pingguString];
第二步:设置字体颜色和大小 (NSForegroundColorAttributeName和NSFontAttributeName只支持ios6以上)
[str addAttribute:NSForegroundColorAttributeNamevalue:(id)[UIColorredColor].CGColorrange:NSMakeRange(0, pingguString1.length)];
[str addAttribute:NSFontAttributeNamevalue:[UIFontsystemFontOfSize:13]range:NSMakeRange(0, pingguString1.length)];
[str addAttribute:NSForegroundColorAttributeNamevalue:[UIColorredColor] range:NSMakeRange(pingguString1.length, pingguString2.length)];
[str addAttribute:NSFontAttributeNamevalue:[UIFontsystemFontOfSize:13]range:NSMakeRange(pingguString1.length, pingguString2.length)];
第三步:NSMutableAttributedString与UILabel关联
UILabel * label = [[UILabelalloc] initWithFrame:rect];
[label setFont:[UIFontsystemFontOfSize:fonSize]];
[label setBackgroundColor:Color];
[label setTextAlignment:alignment];
[label setNumberOfLines:2];
[label setTag:tag];
[label setLineBreakMode:UILineBreakModeWordWrap];
label.attributedText = str;
[self.contentViewaddSubview:label];
[str release];
NSMutableAttributedString 与UILabel 常用使用,布布扣,bubuko.com
NSMutableAttributedString 与UILabel 常用使用
标签:style color 使用 os io for line rgb
原文地址:http://blog.csdn.net/u014624597/article/details/38268363