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