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 ...
随机推荐
- SharePoint客户端js对象模型
'use strict'; var context = SP.ClientContext.get_current(); var user = context.get_web().get_current ...
- Linux audio驱动模型
linux驱动 alsa模型: Linux ALSA声卡驱动之一:ALSA架构简介 Linux ALSA声卡驱动之二:声卡的创建 Linux ALSA声卡驱动之三:PCM设备的创建 Linux ALS ...
- Ajax提交Form表单的一种方法
待提交的表单 <form id="updatePublicKey" enctype="multipart/form-data"> <div c ...
- 下载的js文件本地编辑器打开中文乱码如何解决
今天遇到的小问题,已解决,直接上图 下载直接打开是这样的 用记事本打开 另存为utf-8格式 正常了!
- cobaltstrike安装加破解教程+使用教程
1.先安装java环境= = 1. 下载1.8u121的JAVA JDK (新的java JDK不稳定)!!原因:https://blog.cobaltstrike.com/2017/04/26/ja ...
- Codeforces 725B Food on the Plane
B. Food on the Plane time limit per test:2 seconds memory limit per test:256 megabytes input:standar ...
- AtCoder Grand Contest 013
这场打得蛮菜的,很晚才出BC,还一堆罚时…… A - Sorted Arrays 题目大意:将给定数列划分成单调不增或单调不减的区间,求最少区间数. 贪心即可. #include<cstdio& ...
- HDU 2502 月之数(二进制,规律)
月之数 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submis ...
- HDU2243 考研路茫茫――单词情结
Description 背单词,始终是复习英语的重要环节.在荒废了3年大学生涯后,Lele也终于要开始背单词了. 一天,Lele在某本单词书上看到了一个根据词根来背单词的方法.比如"ab&q ...
- [bzoj1500 维修数列](NOI2005) (splay)
真的是太弱了TAT...光是把代码码出来就花了3h..还调了快1h才弄完T_T 号称考你会不会splay(当然通过条件是1h内AC..吓傻)... 黄学长的题解:http://hzwer.com/28 ...