适用于:当你想对一个字符串中的某几个字符更改颜色,字体。。。

   NSString *string = @"今日营养配餐提供热量1800千卡,需要饮食之外额外补充钙10mg,铁20mg,锌9.5mg,叶酸200μgDFE,维生素D 10ug,维生素B1 1.2mg,维生素B2 1.2mg。";

NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:string];

NSRange range = [string rangeOfString:@"今日营养配餐"];

[attributedString addAttribute:NSForegroundColorAttributeName value:JYEColor(72, 75, 91) range:range];

[attributedString addAttribute:NSFontAttributeName value:[self jyeFontWithName:@"PingFangSC-Medium" size:13] range:range];

hotLabel.attributedText = attributedString;

使用场景:处理 属性字符串 文字居中

NSMutableParagraphStyle *paragrapStyle = [[NSMutableParagraphStyle alloc]init];

paragrapStyle.alignment = NSTextAlignmentCenter;//文字居中属性

    NSString * shareCountStr = [NSString stringWithFormat:@"———已有%@人分享———",self.dishAdviceShareCountString];

NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:shareCountStr];

NSRange range = [shareCountStr rangeOfString:self.dishAdviceShareCountString];//人数 做颜色处理

[attributedString addAttribute:NSForegroundColorAttributeName value:JYEColor(255, 48, 99) range:range];

[attributedString addAttribute:NSFontAttributeName value:[JYEToolModel jyeFontWithName:@"PingFangSC-Regular" size:12] range:range];

[attributedString addAttribute:NSParagraphStyleAttributeName value:paragrapStyle range:range];

shareNumLabel.attributedText = attributedString;

NSMutableAttributedString可变属性字符串的用法的更多相关文章

  1. (转)iOS 属性字符串

    富文本的基本数据类型是NSAttributedString.**属性化字符串**(attributed string)是把属性设置到某些字符上的字符串.属性可以是任何键值对,但是为了实现富文本,则通常 ...

  2. Delphi中stringlist分割字符串的用法

    Delphi中stringlist分割字符串的用法 TStrings是一个抽象类,在实际开发中,是除了基本类型外,应用得最多的. 常规的用法大家都知道,现在来讨论它的一些高级的用法. 1.CommaT ...

  3. Python中用format函数格式化字符串的用法

    这篇文章主要介绍了Python中用format函数格式化字符串的用法,格式化字符串是Python学习当中的基础知识,本文主要针对Python2.7.x版本,需要的朋友可以参考下   自python2. ...

  4. 属性字符串的replaceCharactersInRange方法

    一,实验: 1> 让 range 的 length 参数为0,以下代码输出属性字符串的结果为12354 NSMutableAttributedString *attrStr = [[NSMuta ...

  5. SQL反模式学习笔记6 支持可变属性【实体-属性-值】

    目标:支持可变属性 反模式:使用泛型属性表.这种设计成为实体-属性-值(EAV),也可叫做开放架构.名-值对. 优点:通过增加一张额外的表,可以有以下好处 (1)表中的列很少: (2)新增属性时,不需 ...

  6. 属性字符串(NSAttributedString)的简单应用

    属性字符串NSAttributedString 可以对字符串附加格式信息,由于对于对不同文本片段使用不同的格式,属性字符串类特别合适. IOS 6中对样式文本有了大改善,大部分主要的UIKit控件都允 ...

  7. iOS UILable和属性字符串的使用

    UILable的常用方法和属性 设置文字颜色(默认为黑色) @property(nonatomic,strong) UIColor     *textColor 设置显示文字 @property(no ...

  8. 给iOS开发新手送点福利,简述文本属性Attributes的用法

    给iOS开发新手送点福利,简述文本属性Attributes的用法   文本属性Attributes 1.NSKernAttributeName: @10 调整字句 kerning 字句调整 2.NSF ...

  9. CSS3动画属性animation的用法

    转载: 赞生博客 高端订制web开发工作组 » CSS3动画属性animation的用法 CSS3提供了一个令人心动的动画属性:animation,尽管利用animation做出来的动画没有flash ...

随机推荐

  1. rJava包---R与Java的接口

    1.安装 版本说明:Win10+R3.2.5+JKD1.7+eclipse-jee-mars-R-win32-x86_64 install.packages("rJava") 2. ...

  2. 【转】crontab定时任务中文乱码问题

    转载:http://blog.163.com/rettar@126/blog/static/1216503422012135511740/ 手动执行都很正常的的脚步,添加到定时任务中一直执行失败,日志 ...

  3. requestAnimationFrame制作动画:旋转风车

    在以往,我们在网页上制作动画效果的时候,如果是用javascript实现,一般都是通过定时器和间隔来实现的,出现HTML5之后,我们还可以用CSS3 的transitions和animations很方 ...

  4. FPGA技术的发展历史和动向

    本文关键字:fpga技术,fpga发展, fpga培训,FPGA应用开发入门与典型实例 一.FPGA技术的发展历史 纵观数字集成电路的发展历史,经历了从电子管.晶体管.小规模集成电路到大规模以及超大规 ...

  5. Jquery_jquery中attr和prop的区别

    在高版本的jquery引入prop方法后,什么时候该用prop?什么时候用attr?它们两个之间有什么区别?这些问题就出现了. 关于它们两个的区别,网上的答案很多.这里谈谈我的心得,我的心得很简单: ...

  6. 找到一个Flex中LineChart很好的学习博客

    http://blog.flexexamples.com/category/linechart/ 里面链接复制的时候失效了,请直接点击原页面进行查看 Setting specific minimum ...

  7. [译]FastClick: native-like tapping for touch apps

    原文地址:http://labs.ft.com/2011/08/fastclick-native-like-tapping-for-touch-apps/ 这篇文章是一篇老文了,现在才看到,真是落后啊 ...

  8. javaweb之框架标签(day1 框架标签的使用)

    框架标签 <frameset> --rows:按照行进行划分<frameset rows='80,*'> --rows:按照列进行划分<frameset cols='80 ...

  9. hdu1251 字典树or map

    一道字典树的题,不过看起来用map更为简单 传送门 题意: 给出一堆字符串构成一个字典,求字典里以某字符串为前缀的字符串有几个 思路: 输入字符串时把字符串的前缀全部存进map并标记次数 查询时直接输 ...

  10. [LintCode] Segment Tree Build 建立线段树

    The structure of Segment Tree is a binary tree which each node has two attributes start and end deno ...