本人开发的开发者技术变现资源聚集地,大家支持下,下面是网址

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的更多相关文章

  1. Automake

    Automake是用来根据Makefile.am生成Makefile.in的工具 标准Makefile目标 'make all' Build programs, libraries, document ...

  2. iOS - NSMutableAttributedString富文本的实现

    NSMutableAttributedString继承于NSAttributedString(带属性的字符串)能够简单快速实现富文本的效果;不多说直接上效果图和代码,通俗易懂: (一)效果图: (二) ...

  3. iOS中富文本NSMutableAttributedString的用法

    NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc]initWithString:@"我是富文 ...

  4. Objective C中的ARC的修饰符的使用---- 学习笔记九

    #import <Foundation/Foundation.h> @interface Test : NSObject /** * 默认的就是__strong,这里只是做示范,实际使用时 ...

  5. NSMutableAttributedString(转)

    NSMutableAttributedString计算高度的问题 _label_page2_1 = [[UILabel alloc] init]; _label_page2_1.numberOfLin ...

  6. NSMutableAttributedString常用代码

    NSTextAttachment *attachment = [[NSTextAttachment alloc] init]; attachment.image = [UIImage imageNam ...

  7. Objective的字符串拼接 似乎没有Swift方便,但也可以制做一些较为方便的写法

    NSString *str1 = @"字符串1"; NSString *str2 = @"字符串2"; //在同样条件下,Objective的字符串拼接 往往只 ...

  8. [转] 从 C 到 Objective C 入门1

    转自: http://blog.liuhongwei.cn/iphone/objective-c/ 进军iPhone开发,最大的难点之一就是怪异的Objective C语法了.不过,了解之后才发现,原 ...

  9. Objective C运行时(runtime)

    #import <objc/runtime.h> void setBeingRemoved(id __self, SEL _cmd) { NSLog(@"------------ ...

  10. Objective C ARC 使用及原理

    手把手教你ARC ,里面介绍了ARC的一些特性, 还有将非ARC工程转换成ARC工程的方法 ARC 苹果官方文档 下面用我自己的话介绍一下ARC,并将看文档过程中的疑问和答案写下来.下面有些是翻译,但 ...

随机推荐

  1. Js~(function(){})匿名自执行方法的作用

    匿名自执行方法体(function(){})经常用在设计JS插件上面,它定义相关组件的行为,自动初始化相关属性,而且在页面中可以直接执行,你不需要手动执行它,它被自动被执行! 在设计你的匿名自执行方法 ...

  2. JS 操作 DOM

    定义:文档对象模型(Document Object Model,DOM)是一种用于HTML和XML文档的编程接口.它给文档提供了一种结构化的表示方法,可以改变文档的内容和呈现方式 节点:(例如:< ...

  3. spring容器对bean生命周期的管理三中方式

    spring容器对bean的生命周期管理主要在两个时间点:bean的初始化完成(包括属性值被完全注入),bean的销毁(程序结束,或者引用结束)方式一:使用springXML配置中的init-meth ...

  4. Design3:使用HierarchyID构建数据的分层结构

    1,传统的分层结构是父子结构,表结构中有一个ParentID字段自引用表的主键,表示“归属”关系,例如 create table dbo.emph ( ID int not null primary ...

  5. Render OpenCascade Geometry Curves in OpenSceneGraph

    在OpenSceneGraph中绘制OpenCascade的曲线 Render OpenCascade Geometry Curves in OpenSceneGraph eryar@163.com ...

  6. Android二维码之创建

    由于微信的推出二维码走进了我们的生活,并且越来越多的人们正在发挥着自己的想象力去使用它,来方便我们的生活,我曾经听说过一个笑话,当我们死后,墓碑上不再有墓志铭,而会出现一个记录你一生信息的二维码,当人 ...

  7. NodeJS实战:Express+Mongoose+ejs

    元宵还没到,先向所有朋友拜一个晚年~~~ 文章目录: 1.组件版本号 -- --node -- --express -- --Mongoose 2.初始化项目 firstblood -- --用 ex ...

  8. android中出现Error retrieving parent for item: No resource found that matches the Theme.AppCompat.Light

    styles.xml中<style name="AppBaseTheme" parent="Theme.AppCompat.Light">提示如下错 ...

  9. 最简明的JavaScript闭包解释

    最简明的JavaScript闭包解释 JavaScript是这几年最火的编程语言之一,从前端到服务器端,再到脚本,好像没有一个地方没有JavaScript的身影.这个世界上任何的一种事物的存在必然有其 ...

  10. Android聚合广告AFP的对接系统设计

    工作需要,要对接阿里妈妈的广告聚合平台,简称AFP.对于一般的应用而言,想要流量变现,广告是显而易见的手段,尤其是在中国,打开一个千万级别的用户,肯定有某个地方是有对接广告的,只不过明不明显而已. 阿 ...