码迷,mamicode.com
首页 > 移动开发 > 详细

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

时间:2015-06-23 10:21:43      阅读:213      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!