规则图形(圆形和矩形)阴影填充
1.矩形方案:
这里使用shadow填充
self.rightInfoView.layer.shadowOpacity = 0.5;
self.rightInfoView.layer.masksToBounds = NO;
self.rightInfoView.layer.shadowOffset = CGSizeMake(0, 0);
self.rightInfoView.layer.shadowRadius = 0;
self.rightInfoView.layer.shadowColor = [[UIColor redColor] colorWithAlphaComponent:0.1].CGColor;
CGMutablePathRef squarePath1 = CGPathCreateMutable();
CGPathAddRect(squarePath1, NULL, CGRectMake(0, 0, 414 / 2 * rightpd, yz_height));
self.rightInfoView.layer.shadowPath = squarePath1;
CGPathRelease(squarePath1);
效果:
1.png
圆形方案:
CGContextAddArc(context, 150, 30, 30, 0, 2*PI, 0);
CGContextDrawPath(context, kCGPathFill);
UIColor*aColor = [UIColor colorWithRed:1 green:0.0 blue:0 alpha:1];
CGContextSetFillColorWithColor(context, aColor.CGColor);
CGContextSetLineWidth(context, 3.0);
CGContextAddArc(context, 250, 40, 40, 0, 2*PI, 0);
CGContextDrawPath(context, kCGPathFillStroke);
扇形方案
UIColor*aColor = [UIColor colorWithRed:1 green:0.0 blue:0 alpha:1];
CGContextSetFillColorWithColor(context, aColor.CGColor);
CGContextSetLineWidth(context, 3.0);
CGContextAddArc(context, 250, 40, 40, 0, 2*PI, 0);
CGContextDrawPath(context, kCGPathFillStroke);
非规则图形,梯型方案或者不规则方案
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetStrokeColorWithColor(context, self.yzColor.CGColor);
CGContextSetLineWidth(context, 1.5);//线的宽度
CGContextAddLines(context, sPoints, self.yzPoints.count);//添加线
CGContextDrawPath(context, kCGPathStroke); //根据坐标绘制路径
CGPoint sPoints[4];//坐标点
sPoints[0] = pointzero;
sPoints[1] = point;
sPoints[2] = point1;
sPoints[3] = point3;
CGContextAddLines(context, sPoints, 4);//添加线
//修改画笔颜色
CGContextSetStrokeColorWithColor(context, [UIColor clearColor].CGColor);
CGContextSetLineWidth(context, 0);//线的宽度
CGContextClosePath(context);//封起来
CGContextSetFillColorWithColor(context, [_yzColor colorWithAlphaComponent:0.1].CGColor);//填充颜色
CGContextDrawPath(context, kCGPathFillStroke);
截屏2022-01-14 下午6.33.07.png
网友评论