重写drawrect
{
if (isWithStrikeThrough)
{
CGSize contentSize = [self.text sizeWithFont:self.font constrainedToSize:self.frame.size];
CGContextRef c = UIGraphicsGetCurrentContext();
CGFloat color[4] = {0.667, 0.667, 0.667, 1.0};
CGContextSetStrokeColor(c, color);
CGContextSetLineWidth(c, 2);
CGContextBeginPath(c);
CGFloat halfWayUp = (self.bounds.size.height - self.bounds.origin.y) / 2.0;
CGContextMoveToPoint(c, self.bounds.origin.x, halfWayUp );
CGContextAddLineToPoint(c, self.bounds.origin.x + contentSize.width, halfWayUp);
CGContextStrokePath(c);
}
[super drawRect:rect];
}
本文介绍了一种在iOS开发中通过重写drawRect方法来为UILabel添加删除线效果的技术方案。该方法利用Core Graphics绘制一条贯穿文本中部的直线,以此模拟文本被划掉的效果。
189

被折叠的 条评论
为什么被折叠?



