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 ...
随机推荐
- java不定参数列表---乔老师没讲,但是传智有讲
**public static void sum(int i,int...srgs){** package com.xml; public class dremo1 { public static v ...
- 拍照选择图片(Activity底部弹出)
效果图如下: 第一步 : 显示出的布局文件:alert_dialog.xml <?xml version="1.0" encoding="utf-8"?& ...
- elasticsearch2.x插件之一:marvel(简介)
在 安装插件的过程中,尤其是安装Marvel插件遇到了很多问题,又要下载license.Marvel-agent,又要下载安装Kibana,很多内容 不知道为何这样安装处理.仔细看了看ElasticS ...
- OpenGL 使用GLFW创建全屏窗口
OpenGL 使用GLFW创建全屏窗口 GLFW库里面的glfwCreateWindow()函数是用来创建窗口的函数. 这样函数的原型是: GLFWwindow* glfwCreateWindow(i ...
- R语言:文本(字符串)处理与正则表达式
R语言:文本(字符串)处理与正则表达式 (2014-03-27 16:40:44) 转载▼ 标签: 教育 分类: R 处理文本是每一种计算机语言都应该具备的功能,但不是每一种语言都侧重于处理文本.R语 ...
- Pig Latin JOIN (inner) 与JOIN (outer)的区别
1.内连接(自然连接): 只有两个表相匹配的行才能在结果集中出现 2.外连接: 包括 (1)左外连接(左边的表不加限制) (2)右外连接(右边的表不加限制) (3)全外连接(左右两表都不加限制) 3. ...
- 对Json的一些理解
标准json格式:{"name":"王大昭","url":"https://www.cnblogs.com/codezhao/&q ...
- java线程基础知识----java daemon线程
java线程是一个运用很广泛的重点知识,我们很有必要了解java的daemon线程. 1.首先我们必须清楚的认识到java的线程分为两类: 用户线程和daemon线程 A. 用户线程: 用户线程可以简 ...
- docker私有仓库的搭建
Docker搭建本地私有仓库的详细步骤 Dockers不仅提供了一个中央仓库,同时也允许我们使用registry搭建本地私有仓库.使用私有仓库有许多优点:一.节省网络带宽,针对于每个镜像,不用每个人都 ...
- MongoDB自定义存储数据库文件位置
mongodb下载地址:https://www.mongodb.com/download-center#community 本机安装目录如下: 配置步骤如下: 1.新建文件夹data(文件夹内再建一个 ...