美文网首页
Quartz 2D简单绘制分割线

Quartz 2D简单绘制分割线

作者: 捷克许 | 来源:发表于2018-01-29 22:52 被阅读0次

项目要做说说功能,说说列表cell的内容和评论之间有个带小尖角的分割线,如图红箭头所指。最近在看Quartz 2D文档,所以就学以致用,只需几行代码就绘制出来了。

4DDBD4CA-9D7B-4AD7-A173-D5E65AF31F7C.png

步奏:
1.新建类PCTalkCommentDivideView,继承自UIView
2.重写drawRect:方法
3.使用Quartz 2D绘制分割线
4.将PCTalkCommentDivideView添加到cell中

@implementation PCTalkCommentDivideView

- (void)drawRect:(CGRect)rect {
  CGContextRef context = UIGraphicsGetCurrentContext();
  CGFloat y = rect.size.height-0.5;
  CGContextMoveToPoint(context, 0, y);
  CGContextAddLineToPoint(context, 26, y);
  CGContextAddLineToPoint(context, 30, y-4);
  CGContextAddLineToPoint(context, 34, y);
  CGContextAddLineToPoint(context, rect.size.width, y);
  CGContextSetLineWidth(context, 0.5);
  [UIColor colorWithRed:237/255.0  green:238/255.0 blue:245/255.0 alpha:1];
  CGContextStrokePath(context);
}
@end

我的Quartz 2D笔记:http://blog.csdn.net/dolacmeng/article/details/78953245

相关文章

网友评论

      本文标题:Quartz 2D简单绘制分割线

      本文链接:https://www.haomeiwen.com/subject/xiafzxtx.html