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,并将看文档过程中的疑问和答案写下来.下面有些是翻译,但 ...
随机推荐
- Atitit图像识别的常用特征大总结attilax大总结
Atitit图像识别的常用特征大总结attilax大总结 1.1. 常用的图像特征有颜色特征.纹理特征.形状特征.空间关系特征. 1 1.2. HOG特征:方向梯度直方图(Histogram of O ...
- fir.im Weekly - 论个人技术影响力是如何炼成的
每个圈子都有一群能力强且懂得经营自己的人,技术圈也是如此.本期 fir.im Weekly 一如往期精选了一些实用的 iOS,Android 开发工具和源码分享,还有一些关于程序员的成长 Tips 和 ...
- react7 react 三目运算
<body><!-- React 真实 DOM 将会插入到这里 --><div id="example"></div> <!- ...
- linux配置hosts
linux配置hosts linux下配置hosts和windows下其实就是一样的,找到文件在哪里就好 sudo vim /etc/hosts
- 第五节:表单标签的用法——value绑定和修饰符
1.表单标签的用法--value绑定和修饰符 value绑定的写法:v-bind:value 或者简写 :value 修饰符: lazy , Number , trim . 用法如: v-model ...
- 快速入门系列--WCF--04元数据和异常处理
本章节将进行元数据和异常处理的介绍,这部分内容概念型比较强,可以快速浏览一下就好. 客户端和服务器借助于终结点进行通信,服务的提供者通过一个或者多个终结点将服务发布出来,服务的消费者则通过创建与之匹配 ...
- Nexus3.0私服搭建
官方文档:http://books.sonatype.com/nexus-book/3.0/reference/install.html 1.下载 http://www.sonatype.com/do ...
- JS中实现数组和对象的深拷贝和浅拷贝
数组的拷贝 > 数组的深拷贝,两层 var arr = [[1,2,3],[4,5,6],[7,8,9]]; var arr2 = []; 循环第一层数组 for(var i=0,len=arr ...
- Shader预处理宏、内置状态变量、多版本编译等
预定义shader预处理宏: Target platform: SHADER_API_OPENGL - desktop OpenGL SHADER_API_D3D9 - Direct3D SHADER ...
- WPF中实现验证码功能
其实和winform中的实现差不多,只是由于WPF中控件使用的库与winform中的有区别,大体上还是差不多的,直接看代码: 产生验证码的类:ValidCode.cs public class Val ...