iOS · UILabel加删除线

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了iOS · UILabel加删除线相关的知识,希望对你有一定的参考价值。

创建自定义子类DeleteLineLabel,继承自UILabel,然后在自定义子类DeleteLineLabel中

 

方法一(上下文):

 

 1 - (void)drawRect:(CGRect)rect {
 2     [super drawRect:rect];
 3 
 4     CGContextRef ref = UIGraphicsGetCurrentContext();
 5     
 6     //绘制起点
 7     CGContextMoveToPoint(ref, 0, rect.size.height * 0.5);
 8     //绘制终点
 9     CGContextAddLineToPoint(ref, rect.size.width, rect.size.height * 0.5);
10     //完成绘制
11     CGContextStrokePath(ref);
12 
13     
14 }

 

方法二(画矩形):

 

 1 - (void)drawRect:(CGRect)rect {
 2     // 调用super的drawRect:方法,会按照父类绘制label的文字
 3     [super drawRect:rect];
 4     
 5     // 取文字的颜色作为删除线的颜色(同文字颜色,可不写)
 6     [self.textColor set];
 7 
 8     // 绘制(找到label的中间位置)
 9     UIRectFill(CGRectMake(0, rect.size.height * 0.5, rect.size.width, 1));
10     
11 }

 

 

完成效果:

 技术分享

 

以上是关于iOS · UILabel加删除线的主要内容,如果未能解决你的问题,请参考以下文章

Python 操作Redis

python爬虫入门----- 阿里巴巴供应商爬虫

Python词典设置默认值小技巧

《python学习手册(第4版)》pdf

Django settings.py 的media路径设置

Python中的赋值,浅拷贝和深拷贝的区别