首页 > 移动平台 > 详细

iOS开发实现Label中多颜色多字体

时间:2016-01-26 20:06:18      阅读:183      评论:0      收藏:0      [点我收藏+]

  UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(8, 100, 300, 30)];

    label.textColor = wordGaryColor;  //未专门设置的字体颜色

    NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:@"公司简介:发挥收到后即可圣诞节快发吧士大夫深刻的房价高速度开放和山东矿机山东科技楼粉红是大家分工"];

    [str addAttribute:NSForegroundColorAttributeName value:commonColor range:NSMakeRange(0,5)];

   [str addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(6,12)];
   [str addAttribute:NSForegroundColorAttributeName value:[UIColor greenColor] range:NSMakeRange(19,6)];
   [str addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:19] range:NSMakeRange(0, 5)];
   [str addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"HelveticaNeue-Bold" size:30.0] range:NSMakeRange(6, 12)];
   [str addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Courier-BoldOblique" size:30.0] range:NSMakeRange(19, 6)];

    label.attributedText = str;

    [self.view addSubview:label];

iOS开发实现Label中多颜色多字体

原文:http://www.cnblogs.com/yyt-hehe-yyt/p/5161209.html

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