我绘制了 UIButtons 图像的一部分,单击清除选项后,我需要将按钮图像重置为第一个(删除绘图)。我用 setImage 属性设置了 UIButton 的图像,但它不起作用,如何从图像中清除绘图?我使用以下代码在 UIImage 上绘图,
UIImageView *imgView =[[UIImageView alloc]init];
UIGraphicsBeginImageContext(self.frame.size);
[imgView.image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), self.drawingWidth);
CGContextSetStrokeColorWithColor(UIGraphicsGetCurrentContext(),lipColor.CGColor);
CGContextSetAlpha(UIGraphicsGetCurrentContext(), self.currntAlpha);
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
CGContextStrokePath(UIGraphicsGetCurrentContext());
CGContextFlush(UIGraphicsGetCurrentContext());
CGContextSetBlendMode(UIGraphicsGetCurrentContext(), kCGBlendModeOverlay);
imgView.image = UIGraphicsGetImageFromCurrentImageContext();
imgView.frame=CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);// Set frame for imageView
[self.imageView addSubview:imgView];
UIGraphicsEndImageContext();
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextClearRect(context, self.bounds);
imgView.layer.shadowOffset = CGSizeZero;
imgView.layer.masksToBounds = NO;
imgView.alpha=0.05;
lastPoint=currentPoint;
self.layer.shadowOpacity=0.01;
任何帮助深表感谢!!!!!!