CGContext 绘画简单的聊天框
圆弧画法
CGContextMoveToPoint(context, point3.x, point3.y);
CGContextAddArcToPoint(context,point4.x, point4.y,point5.x, point5.y,6.0);
point3 起点 point4 拐点 point5 终点
聊天框 完整代码
- (void)drawRect:(CGRect)rect {
// Drawing code
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetStrokeColorWithColor(context, [UIColor secondaryLabelColor].CGColor);//线条颜色
CGContextSetLineWidth(context, 1.0);//线条宽度
CGContextBeginPath(context);
CGFloatpointX =100;
CGPointpoint1 =CGPointMake(pointX,Triangleheight);
CGPointpoint2 =CGPointMake(pointX+TriangleWidth/2,0);
CGPoint point3 = CGPointMake(pointX+TriangleWidth, Triangleheight);
CGPoint point4 = CGPointMake(self.bounds.size.width-1, Triangleheight);
CGPoint point5 = CGPointMake(self.bounds.size.width-1, self.bounds.size.height-1);
CGPoint point6 = CGPointMake(1, self.bounds.size.height-1);
CGPointpoint7 =CGPointMake(1,Triangleheight);
CGContextMoveToPoint(context, point1.x, point1.y);
CGContextAddLineToPoint(context, point2.x, point2.y);
CGContextAddLineToPoint(context, point3.x, point3.y);
CGContextAddArcToPoint(context,point4.x, point4.y,point5.x, point5.y,6.0);
CGContextAddArcToPoint(context,point5.x, point5.y, point6.x, point6.y,6.0);
CGContextAddArcToPoint(context,point6.x, point6.y, point7.x, point7.y,6.0);
CGContextAddArcToPoint(context,point7.x, point7.y, point1.x, point1.y,6.0);
CGContextAddLineToPoint(context, point1.x, point1.y);
CGContextStrokePath(context);
}