码迷,mamicode.com
首页 > 移动开发 > 详细

iOS · UILabel加删除线

时间:2016-12-28 01:42:40      阅读:378      评论:0      收藏:0      [点我收藏+]

标签:pat   ddl   矩形   pre   颜色   move   上下文   delete   stroke   

创建自定义子类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加删除线

标签:pat   ddl   矩形   pre   颜色   move   上下文   delete   stroke   

原文地址:http://www.cnblogs.com/wronganswer/p/6227721.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!