iOS 设置文本中指定某段文本的颜色 大小
NSString *money = @"300";
NSString *perStr = @"元/时";
NSString *text = [NSString stringWithFormat:@"%@%@",money,perStr];
if ([self.currentPriceLabel respondsToSelector:@selector(setAttributedText:)]) {
NSDictionary *attribs = @{
NSForegroundColorAttributeName:self.currentPriceLabel.textColor,
NSFontAttributeName:self.currentPriceLabel.font
};
NSMutableAttributedString *attributedText =
[[NSMutableAttributedString alloc] initWithString:text
attributes:attribs];
// Red text attributes
//#5773de
UIColor *aColor = RED_COLOR;
NSRange redTextRange =[text rangeOfString:money];// * Notice that usage of rangeOfString in this case may cause some bugs - I use it here only for demonstration
[attributedText setAttributes:@{NSForegroundColorAttributeName:aColor,NSFontAttributeName:[UIFontboldSystemFontOfSize:16]} range:redTextRange];
self.currentPriceLabel.attributedText = attributedText;
}
iOS 设置文本中指定某段文本的颜色 大小的更多相关文章
- php 通过 strtr 方法来替换文本中指定的内容
通过在文本中指定待替换的内容,如: [{name}] [{age}] 格式可以自己定义, 大概过程: 在文本中定义需要替换的文本内容: 以键值对的方式 组织数据(数组): 用 file_get_con ...
- 如何使用JS脚本从HTML中分离图片标签与文本,替换文本中指定的内容并加粗(原创)
var html='ddfsdfsdfdsd dfsdfsdffds<img _src="http://localhost:8490/60E86EA7-FE7B-44BF-8270-4 ...
- Zend Studio 12.0.2正式版发布和破解方法,zend studio 12.0.1汉化,相式设置为Dreamweaver,空格缩进为4个, 代码默认不折叠的设置,Outline中使用的图形标志,代码颜色之eot设置。
背景:zend studio 12.0.2 修复了一个12.0.1的: Fixed problem with referenced variables marked as undefined,我都说 ...
- cut 从文本中提取一段文字并输出
1.命令功能 cut 从每个文件中截取选定部分并输出. 2.语法格式 cut option file 参数说明 参数 参数说明 -b (–bytes) 字节 -c (--characters) 字 ...
- 扩展jQuery---选中指定索引的文本
<script type="text/javascript"> //1.扩展jQuery $.fn.selectRange = function (start, end ...
- iOS 设置Label中特定的文字大小和颜色
直接上代码: _price = @"27"; NSMutableAttributedString *attributedString = [[NSMutableAttributed ...
- 设置listContrl中指定行的颜色
在MFC中 自己通过手动拖放CListCtrl控件来制作自己的表格: 目的: 将指定item的行更该颜色: 步骤: 1,在窗口中拖放CListCtrl控件, 单击右键 创建控件对象: CListCtr ...
- 删除string类型字符串中指定字符串段
1.实现背景 在插入list行时用邮件的MessageID给对应行命名. 在回复全部邮件时,收件人变为之前收件人中出去“自己”同时加入之前发件人,抄送人还是之前的抄送人,密送人不用管,直接不用带. 在 ...
- ios 取出subviews中指定subview
for(UIView *view in subviews){ if(view.tag == 998) { //根据tag判断 } if([view isKindOfClass:[UIImageView ...
随机推荐
- uboot中 make xxx_config 的作用(以make smdk2410_config为例)
1.创建到目标板相关文件的链接 ln -s asm-arm asm ln -s arch-s3c24x0 asm-arm/arch ln -s proc-armv asm-arm/proc 2.创建i ...
- Struts2+Spring+Hibernate环境搭建
struts-2.3.20 spring-4.1.4 hibernate-4.3.8 slf4j-1.7.10 1.在MySQL中建立数据库 mysql> create database myo ...
- Vue 组件之 Router
Vue 组件之 Router Vue 开发单页应用的时候,免不了使用Vue组件.在单页应用上如何进行组件切换? 结构如下图所示: 主页面包含Foo组件与Bar组件,在主页面中可以进行Foo与 Bar的 ...
- ZOJ3602:Count the Trees
我是在neuqvj上交的这题:http://vj.acmclub.cn/problem/viewProblem.action?id=17848 本来是挺容易的树同构题,可是节点数比较多,愣是把普通ha ...
- POJ 1655 Balancing Act【树的重心】
Balancing Act Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 14251 Accepted: 6027 De ...
- [bzoj1301] [LLH邀请赛]参观路线
本题同bzoj1098 用个并查集,把连续的被访问过的点并起来..这样就不会尝试已经走过的点了. #include<cstdio> #include<iostream> #in ...
- 互联网App应用程序测试流程及测试总结
互联网App应用程序测试流程及测试总结 1. APP测试基本流程 1.1流程图 仍然为测试环境 Pass 1.2测试周期 测试周期可按项目的开发周期来确定测试时间,一般测试时间为两三周(即15个工作日 ...
- myEclipse配置SVN
方法三:直接解压 下载SVN插件:site-1.6.10.zip 解压后将其全部文件拷贝至:D:\Program Files\Genuitec\MyEclipse 8.5\drop ...
- IDEA for Mac注册码使用
尼玛,一不注意把磁盘抹掉了,重新下idea发现 之前的破解方法失效了 之前所有的 idea 授权服务器已遭JetBrains封杀,所以重新下载后 用之前的方法已经然并卵了,苦苦google后,发现新大 ...
- ngRx 官方示例分析 - 1. 介绍
ngRx 的官方示例演示了在具体的场景中,如何使用 ngRx 管理应用的状态. 示例介绍 示例允许用户通过查询 google 的 book API 来查询图书,并保存自己的精选书籍列表. 菜单有两 ...