objective-c NSMutableAttributedString
本人开发的开发者技术变现资源聚集地,大家支持下,下面是网址
https://www.baiydu.com
NSMutableAttributedString 是一个很强悍的富文本处理字符串,可以方便的实现一个字符串中某个字符的样式处理。我把我下面代码实现的功能步骤说一下:首先拼接两个字符串,然后给前前半部分和后半部分字符串分别实现不同样式,最后在给后半部分的字符串增加删除线.... 如果不用到NSMutableAttributedString 实现起来不但麻烦不说,而且不能保证百分之百的准确: 下面先截图 然后上代码

(←就是它了)
NSDictionary *singleDictionary=[[NSDictionary alloc]initWithObjectsAndKeys:@"pic1",@"imagePath",@"雅致汉斯套餐",@"title",@"重庆only you婚礼策划",@"content",@"6666",@"currentPrice",@"8888",@"truePrice", nil];
//价格
UILabel *PriceLabel=[[UILabel alloc]initWithFrame:CGRectMake(DEVICE_Width*0.5+6,89-22,DEVICE_Width*0.5-6, 15)];
PriceLabel.textColor=COLOR(249, 135, 164);
PriceLabel.font=[UIFont systemFontOfSize:15]; PriceLabel.text= [NSString stringWithFormat:@"%@%@%@%@",@"¥",[singleDictionary objectForKey:@"currentPrice"],@" ¥",[singleDictionary objectForKey:@"truePrice"]];
NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString: PriceLabel.text];
[str addAttribute:NSForegroundColorAttributeName value:COLOR(249, 135, 164) range:NSMakeRange(0,str.length)]; //设置字体颜色
[str addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Arial" size:15] range:NSMakeRange(0, str.length)]; //设置字体大小
[str addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Arial" size:11]range:NSMakeRange(0, 1)];
NSString *getCutStr= [singleDictionary objectForKey:@"currentPrice"];
[str addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Arial" size:11] range:NSMakeRange(getCutStr.length+2, str.length-(getCutStr.length+2))]; //设置字体大小 [str addAttribute:NSForegroundColorAttributeName value:COLOR(149,150,151) range:NSMakeRange(getCutStr.length+2, str.length-(getCutStr.length+2))]; //设置字体颜色 //删除线
int beginThroughIndex= [NSString stringWithFormat:@"%@", [singleDictionary objectForKey:@"currentPrice"]].length+3;
[str addAttribute:NSStrikethroughStyleAttributeName value:@(NSUnderlinePatternSolid|NSUnderlineStyleSingle) range:NSMakeRange(beginThroughIndex, str.length-beginThroughIndex)];
[str addAttribute:NSStrikethroughColorAttributeName value:COLOR(149,150,151) range:NSMakeRange(beginThroughIndex, str.length-beginThroughIndex)];
PriceLabel.attributedText = str;
PriceLabel.textAlignment=NSTextAlignmentLeft;
PriceLabel.numberOfLines = 0;
[cell addSubview:PriceLabel];
本人创业做的一款androidApp, 下载量已经有2000多万,各种当前热门的网络手机奖励红包全部集成,另外还有热门电影和淘宝高额优惠券!很适合各类型的用户。

objective-c NSMutableAttributedString的更多相关文章
- Automake
Automake是用来根据Makefile.am生成Makefile.in的工具 标准Makefile目标 'make all' Build programs, libraries, document ...
- iOS - NSMutableAttributedString富文本的实现
NSMutableAttributedString继承于NSAttributedString(带属性的字符串)能够简单快速实现富文本的效果;不多说直接上效果图和代码,通俗易懂: (一)效果图: (二) ...
- iOS中富文本NSMutableAttributedString的用法
NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc]initWithString:@"我是富文 ...
- Objective C中的ARC的修饰符的使用---- 学习笔记九
#import <Foundation/Foundation.h> @interface Test : NSObject /** * 默认的就是__strong,这里只是做示范,实际使用时 ...
- NSMutableAttributedString(转)
NSMutableAttributedString计算高度的问题 _label_page2_1 = [[UILabel alloc] init]; _label_page2_1.numberOfLin ...
- NSMutableAttributedString常用代码
NSTextAttachment *attachment = [[NSTextAttachment alloc] init]; attachment.image = [UIImage imageNam ...
- Objective的字符串拼接 似乎没有Swift方便,但也可以制做一些较为方便的写法
NSString *str1 = @"字符串1"; NSString *str2 = @"字符串2"; //在同样条件下,Objective的字符串拼接 往往只 ...
- [转] 从 C 到 Objective C 入门1
转自: http://blog.liuhongwei.cn/iphone/objective-c/ 进军iPhone开发,最大的难点之一就是怪异的Objective C语法了.不过,了解之后才发现,原 ...
- Objective C运行时(runtime)
#import <objc/runtime.h> void setBeingRemoved(id __self, SEL _cmd) { NSLog(@"------------ ...
- Objective C ARC 使用及原理
手把手教你ARC ,里面介绍了ARC的一些特性, 还有将非ARC工程转换成ARC工程的方法 ARC 苹果官方文档 下面用我自己的话介绍一下ARC,并将看文档过程中的疑问和答案写下来.下面有些是翻译,但 ...
随机推荐
- 大叔也说Xamarin~Android篇~支付宝SDK的集成
回到目录 首先做为支付宝SDK它提供了多种平台,网页版,wap版,IOS版,android版等等,今天主要说一下在xamarin里使用android平台的sdk的方法,在网上介绍这块的文章不多,大叔本 ...
- MVVM架构~knockoutjs系列之验证信息自定义输出~续
返回目录 上一讲中,我以一个实际中的例子说明了knockoutjs的自定义验证功能,在使用过程中,出现了一个问题,当然了不是问题,只是一种需求,上一讲中自定义验证的表现是:当页面加载后,自动显示有问题 ...
- 来吧!带你玩转 Excel VBA
来吧!带你玩转 Excel VBA 从错失良机到艰辛的DOS征程,从坎坷购机自学路到转机起程,从爱好到事业,他从一个完全不懂电脑的人到VBA高级应用者,一切全是自学…… 我是罗刚君,来自四川的一个小县 ...
- 转【】浅谈sql中的in与not in,exists与not exists的区别_
浅谈sql中的in与not in,exists与not exists的区别 1.in和exists in是把外表和内表作hash连接,而exists是对外表作loop循环,每次loop循环再对内表 ...
- java中Comparable实现对象的比较
/* class A implements Comaprable<A>{ } 那么 A x = new A(); 类关系图 Object o = A; Object Comparable ...
- 【目录】Newlife XCode组件相关文章目录
本博客所有文章分类的总目录链接:本博客博文总目录-实时更新 1.Newlife XCode组件相关文章目录 1.Newlife XCode组件资源目录汇总[2013年版] 2.Newlife ...
- c#基础之数组
最近看了c#的数组,比c++的数组更加直接,.net也提供了很多直接直接操纵数组的方法,非常方便,所以就想做个总结. 利用数组,我们可以使用变量来声明相同类型的多个数据项的集合,数组中的每个数据使用索 ...
- 【GIT】使用Git命令窗口将本地工程提交至远程GitHub
目标: 1.解决的问题是如何通过Git命令窗口将本地工程提交至GitHub. 2.方便园友的同时也方便自己以后解决此类问题. 步骤: 1.首先登陆GitHub网站https://github.com/ ...
- [java] 注释以及javadoc使用简介-汇率换算器的实现-插曲3
[java] 注释以及javadoc使用简介-汇率换算器的实现-插曲3 // */ // ]]> [java] 注释以及javadoc使用简介-汇率换算器的实现-插曲3 Table of C ...
- java设计模式学习(-)
在我目前看来博客的作用就是笔记了,所谓的原创也仅仅是复制了别人的东西实践了一下,但为了学习记忆确实要记录下来.在这里感谢网络各处的资源,原谅我对资源的索取. 接下来每天开始学以则设计模式或者几天学一则 ...