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 设置文本中指定某段文本的颜色 大小的更多相关文章

  1. php 通过 strtr 方法来替换文本中指定的内容

    通过在文本中指定待替换的内容,如: [{name}] [{age}] 格式可以自己定义, 大概过程: 在文本中定义需要替换的文本内容: 以键值对的方式 组织数据(数组): 用 file_get_con ...

  2. 如何使用JS脚本从HTML中分离图片标签与文本,替换文本中指定的内容并加粗(原创)

    var html='ddfsdfsdfdsd dfsdfsdffds<img _src="http://localhost:8490/60E86EA7-FE7B-44BF-8270-4 ...

  3. 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,我都说 ...

  4. cut 从文本中提取一段文字并输出

    1.命令功能 cut 从每个文件中截取选定部分并输出. 2.语法格式 cut  option  file 参数说明 参数 参数说明 -b (–bytes) 字节 -c (--characters) 字 ...

  5. 扩展jQuery---选中指定索引的文本

    <script type="text/javascript"> //1.扩展jQuery $.fn.selectRange = function (start, end ...

  6. iOS 设置Label中特定的文字大小和颜色

    直接上代码: _price = @"27"; NSMutableAttributedString *attributedString = [[NSMutableAttributed ...

  7. 设置listContrl中指定行的颜色

    在MFC中 自己通过手动拖放CListCtrl控件来制作自己的表格: 目的: 将指定item的行更该颜色: 步骤: 1,在窗口中拖放CListCtrl控件, 单击右键 创建控件对象: CListCtr ...

  8. 删除string类型字符串中指定字符串段

    1.实现背景 在插入list行时用邮件的MessageID给对应行命名. 在回复全部邮件时,收件人变为之前收件人中出去“自己”同时加入之前发件人,抄送人还是之前的抄送人,密送人不用管,直接不用带. 在 ...

  9. ios 取出subviews中指定subview

    for(UIView *view in subviews){ if(view.tag == 998) { //根据tag判断 } if([view isKindOfClass:[UIImageView ...

随机推荐

  1. lodash源码分析之List缓存

    昨日我沿着河岸/漫步到/芦苇弯腰喝水的地方 顺便请烟囱/在天空为我写一封长长的信 潦是潦草了些/而我的心意/则明亮亦如你窗前的烛光/稍有暧昧之处/势所难免/因为风的缘故 --洛夫<因为风的缘故& ...

  2. hdu_1010_Tempter of the Bone_dfs

    题意:给出一个地图,起点和终点,四通路(上下左右),问在一定的时间内可以走出这个地图吗 题解:首先这个题意一定要好好读,很容易读错题,理解成最短路径小于给定时间就可以出去,其实是不可以的,必须要在给定 ...

  3. hdu_3003Pupu(快速幂)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3003 Pupu Time Limit: 2000/1000 MS (Java/Others)    M ...

  4. Java简历与面试

    尊重原创:http://blog.csdn.net/love_java_cc/article/details/78292347 Java就业指导   想要成为合格的Java程序员或工程师到底需要具备哪 ...

  5. 算法-java代码实现希尔排序

    希尔排序 第8节 希尔排序练习题 对于一个int数组,请编写一个希尔排序算法,对数组元素排序. 给定一个int数组A及数组的大小n,请返回排序后的数组.保证元素小于等于2000. 测试样例: [1,2 ...

  6. WebClient.DownLoadString报错:连接被意外关闭

    调用WebClient的DownLoadString方法调用接口,当数据量比较小的时候(十几条数据)一切正常.后来对方突然放了一千多条数据,然后就报错了:连接被意外关闭. 先是以为是对方接口没有在输出 ...

  7. Dig out WeChat deleted chat messages on Android Phone

    As we know that WeChat will wipe deleted chat messages. That's why forensic guys could  not dig out ...

  8. 【开发技术】 java和JSP和JavaScript有什么区别

    JSP全称是:java server page,意思是基于JAVA服务器的网页技术,跟asp,php一样,都是网页制作用的语言 JavaScript:也成为JS,跟JAVA没啥关系,就是赶时髦起个这名 ...

  9. eclipse出现错误:he type java.util.Map$Entry cannot be resolved. It is indirectly referenced

    eclipse出现错误:he type java.util.Map$Entry cannot be resolved. It is indirectly referenced jre 换成6的就好了选 ...

  10. c#动态编译并执行字符串

    比较简单,步骤是这样的 string -> compiler -> assembly -> reflection -> execution 直接上代码: using Syste ...