首页 > 移动平台 > 详细

ios开发 之 设置多种文字颜色

时间:2015-06-23 10:18:46      阅读:279      评论:0      收藏:0      [点我收藏+]
 UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 300, 100)];
    label.numberOfLines = 0;
    label.center = self.view.center;
    
    NSMutableAttributedString * str = [[NSMutableAttributedString alloc]initWithString:@"你说你最爱丁香花,因为你的名字就是它,多么忧郁的花,多愁善感的人啊!"];

    NSDictionary * dict = @{NSForegroundColorAttributeName:[UIColor redColor],NSBackgroundColorAttributeName:[UIColor orangeColor]};
    [str addAttributes:dict range:NSMakeRange(9, 9)];
    
    NSDictionary * dict1 = @{NSForegroundColorAttributeName:[UIColor blueColor],NSBackgroundColorAttributeName:[UIColor greenColor]};
    [str addAttributes:dict1 range:NSMakeRange(19, 6)];
    label.attributedText = str;
    [self.view addSubview:label];


ios开发 之 设置多种文字颜色

原文:http://my.oschina.net/linxiaoxi1993/blog/469561

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