博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
NSMutableAttributedString(改变文字颜色)
阅读量:4614 次
发布时间:2019-06-09

本文共 1011 字,大约阅读时间需要 3 分钟。

//类型
//创建一个label   
UILabel *label1=[[UILabel alloc]initWithFrame:CGRectMake(130, 60,250, 150)];
    [self.window addSubview:label1];
    label1.text=@"评分:7.1   (4925评论)\n20140901        date\n126min         runtime\n动作/冒险/惊悚        genres\n美国|法国        country";
    label1.numberOfLines=0;
//类型字体颜色
//创建NSMutableAttributedString   
NSMutableAttributedString *mstring=[[[NSMutableAttributedString alloc]initWithString:@"评分:7.1   (4925评论)\n20140901        date\n126min         runtime\n动作/冒险/惊悚        genres\n美国|法国        country "] autorelease];
//定义  
[mstring addAttribute:NSForegroundColorAttributeNamevalue:[UIColorredColor]  range:NSMakeRange(34, 4)];
    [mstring addAttribute:NSForegroundColorAttributeName value:[UIColor redColor]  range:NSMakeRange(54, 7)];
    [mstring addAttribute:NSForegroundColorAttributeName value:[UIColor redColor]  range:NSMakeRange(78, 6)];
   
    [mstring addAttribute:NSForegroundColorAttributeName value:[UIColor redColor]  range:NSMakeRange(99, 7)];
   //将 NSMutableAttributedString赋给UIlabel
    label1.attributedText=mstring;

转载于:https://www.cnblogs.com/lsh1234/p/4902710.html

你可能感兴趣的文章
js原生Ajax的封装与使用
查看>>
周总结6
查看>>
PostgreSQL 务实应用(二/5)插入冲突
查看>>
一种公众号回复关键词机制
查看>>
java多线程入门学习(一)
查看>>
基于 Web 的 Go 语言 IDE - Wide 1.1.0 公布!
查看>>
nyist oj 138 找球号(二)(hash 表+位运算)
查看>>
Movidius软件手册阅读 2017-09-04
查看>>
ytu 1910:字符统计(水题)
查看>>
201671030110 姜佳宇 实验三作业互评与改进
查看>>
mysql-5.6.15 开启二进制文件
查看>>
python的沙盒环境--virtualenv
查看>>
软件自动化测试——入门、进阶与实战
查看>>
BZOJ1878 [SDOI2009]HH的项链 树状数组 或 莫队
查看>>
BZOJ3675 [Apio2014]序列分割 动态规划 斜率优化
查看>>
2016.10.24 继续学习
查看>>
产品功能对标 - 服务授权管理
查看>>
各地IT薪资待遇讨论
查看>>
splay入门
查看>>
带CookieContainer进行post
查看>>