ios Lable 添加删除线
遇到坑了:
NSString *goodsPrice = @"230.39";
NSString *marketPrice = @"299.99";
NSString* prceString = [NSString stringWithFormat:@"%@ %@",goodsPrice,marketPrice];
DLog(@"----打印--%@---",prceString); NSMutableAttributedString*attributedString = [[NSMutableAttributedString alloc]initWithString:prceString]; [attributedString addAttribute:NSForegroundColorAttributeName value:RGBACOLOR(, , , ) range:NSMakeRange(, goodsPrice.length)]; [attributedString addAttribute:NSStrikethroughStyleAttributeName value:@(NSUnderlinePatternSolid|NSUnderlineStyleSingle) range:[prceString rangeOfString:marketPrice]]; [attributedString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:] range:[prceString rangeOfString:marketPrice]]; [attributedString addAttribute:NSForegroundColorAttributeName value:[UIColor lightGrayColor] range:[prceString rangeOfString:marketPrice]];
[priceLabel setAttributedText:attributedString];
我感觉下面的代码写的没有问题,但是运行起来怎么就不行了呢

真是百思不得姐,然后各种百度:http://stackoverflow.com/questions/43070335/nsstrikethroughstyleattributename-how-to-strike-out-the-string-in-ios-10-3

然后然后...,换了种写法:
NSString *goodsPrice = @"230.39";
NSString *marketPrice = @"299.99";
NSString* prceString = [NSString stringWithFormat:@"%@ %@",goodsPrice,marketPrice];
DLog(@"----打印--%@---",prceString); NSMutableAttributedString *attritu = [[NSMutableAttributedString alloc]initWithString:prceString];
[attritu addAttributes:@{
NSStrikethroughStyleAttributeName:@(NSUnderlineStyleThick),
NSForegroundColorAttributeName:
[UIColor lightGrayColor],
NSBaselineOffsetAttributeName:
@(),
NSFontAttributeName: [UIFont systemFontOfSize:]
} range:[prceString rangeOfString:marketPrice]];
priceLabel.attributedText = attritu;

如果上面的问题还有问题,我们还可以用其他方式实现这种效果
新建一个集成 UILabel 的子类,
- (void)drawRect:(CGRect)rect
{
// 调用super的drawRect:方法,会按照父类绘制label的文字
[super drawRect:rect]; // 取文字的颜色作为删除线的颜色
[self.textColor set];
CGFloat w = rect.size.width;
CGFloat h = rect.size.height;
// 绘制(这个数字是为了找到label的中间位置,0.35这个数字是试出来的,如果不在中间可以自己调整)
UIRectFill(CGRectMake(, h * 0.5, w, ));
}
别忘了sizeToFit 不然线会根据空间的 width来画的
YJlale *priceLabel = [[YJlale alloc] initWithFrame:CGRectMake(, , , )];
priceLabel.textColor = [UIColor redColor];
priceLabel.text = @"";
[priceLabel sizeToFit];
[self.view addSubview:priceLabel];

ios Lable 添加删除线的更多相关文章
- iOS label 添加删除线(删划线)遇到的坑
1.添加删划线方法遇到的问题 -(void)lastLabelDeal:(NSString *)str1 string:(NSString *)str2 label:(UILabel *)label{ ...
- iOS 为label添加删除线
UILabel *testLabel = [[ UILabel alloc] initWithFrame:CGRectMake(, , , )]; testLabel.numberOfLines = ...
- iOS · UILabel加删除线
创建自定义子类DeleteLineLabel,继承自UILabel,然后在自定义子类DeleteLineLabel中 方法一(上下文): - (void)drawRect:(CGRect)rect { ...
- Android中TextView添加删除线
项目中的需求~~~~ 商城中物品的一个本身价格,还有一个就是优惠价格...需要用到一个删除线. public class TestActivity extends Activity { private ...
- python 对过时类或方法添加删除线的方法
class Cat(Animal): def __init__(self): import warnings warnings.warn("Cat类带删除线了", Deprecat ...
- iOS创建带删除线和价钱符号的Label
效果显示如下: 只需要子类化Label,重写DrawRect()方法即可: #import "MyLabel.h" @implementation MyLabel - (insta ...
- Android: 在 TextView 里使用删除线
Android: 在 TextView 里使用删除线 分类: Android2014-09-25 13:17 3431人阅读 评论(0) 收藏 举报 以编程的方式添给 TextView 添加删除线: ...
- iOS仿网易新闻栏目拖动重排添加删除效果
仿网易新闻栏目选择页面的基本效果,今天抽了点时间教大家如何实现UICollectionView拖动的效果! 其实实现起来并不复杂,这里只是基本的功能,没有实现细节上的修改,连UI都是丑丑的样子,随手画 ...
- iOS-属性字符串添加下划线、删除线
常用到的属性字符串 ///定义属性字符串NSMutableAttributedString *att = [[NSMutableAttributedString alloc]initWithStrin ...
随机推荐
- Unity堆内存优化
unity中减少堆内存分配以减少垃圾回收处理:只有局部变量且为值类值的变量是从stack栈中分配内存,其它所有情况都是从heap堆中分配内在.* 缓存获取到的数据.* 频繁被调用的函数中尽量少的分配空 ...
- IDEA拷贝git上的最新项目资源
File->new ->project version control->git-> 进入项目git对应的网址,选择第一个backstop,复制url: 输入git用户名和密码 ...
- How to install Samba server on Ubuntu 12.04
Part 1: Configuring anonymous share with samba server To install the samba package,enter the followi ...
- 第一个 Django 应用
1. 创建项目 1.1 新建项目 首先新建一个项目,名为 mysite,命令如下: django-admin startproject mysite # 或用 django-admin.py 运行成功 ...
- cookie 单值设置
- Vue中使用jquery
在vue项目中,需要实现某些特定的功能时,使用mvvm模式不易实现.因此引入jquery包来完成需求 npm install jqueryimport $ from jquery //在需要使用的页面 ...
- HTML5 为 <input> 增加的属性 ; 为 <form> 增加的如需属性
HTML5 为 <input> 增加了如下属性: autocomplete autofocus form formaction formenctype formmethod formnov ...
- python 基于 wordcloud + jieba + matplotlib 生成词云
词云 词云是啥?词云突出一个数据可视化,酷炫.以前以为很复杂,不想python已经有成熟的工具来做词云.而我们要做的就是准备关键词数据,挑一款字体,挑一张模板图片,非常非常无脑.准备好了吗,快跟我一起 ...
- Mysql-5-数据表的基本操作
1.创建表:之前需要use database database_name 然后create table 表名(): 例:创建员工表tb_employee1,结构如下表所示 字段名称 数据类型 备注 i ...
- retrying模块的安装及使用
安装retrying模块: win10用户在联网的情况下直接在cmd.exe里面键入"pip install retrying" 即可安装retrying模板 在网页正常浏览的过 ...