遇到一个需求,要求设置一个三角形,并且没有切图,所以只能自己绘制了,
这里使用贝塞尔曲线结合CAShaperLayer绘制,直接上代码
UIColor *color = [UIColor colorFromHexString_au:@"0xcccccc"];
UIBezierPath *path = [[UIBezierPath alloc] init];
[path moveToPoint:CGPointMake(0, rect.size.height/2)];
[path addLineToPoint:CGPointMake(rect.size.width, 0)];
[path addLineToPoint:CGPointMake(rect.size.width, rect.size.height)];
[path closePath];
CAShapeLayer *layer = [[CAShapeLayer alloc] init];
layer.strokeColor = [UIColor clearColor].CGColor;
layer.fillColor = color.CGColor;
layer.path = path.CGPath;
[self.layer addSublayer:layer];