首页 > 其他 > 详细

NSMutableAttributedString 与UILabel 常用使用

时间:2014-07-29 15:13:08      阅读:292      评论:0      收藏:0      [点我收藏+]

 第一步: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 常用使用

原文:http://blog.csdn.net/u014624597/article/details/38268363

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!