开发者

how to erase subviews from a view?

开发者 https://www.devze.com 2023-02-17 08:19 出处:网络
This is my code. I am using this code to erase only the imageView.image, but I want to erase the imageview subviews also. How can I erase the subviews from imageView?

This is my code. I am using this code to erase only the imageView.image, but I want to erase the imageview subviews also. How can I erase the subviews from imageView?

UIGraphicsBeginImageContext(imageView.开发者_如何转开发frame.size);
[imageView.image drawInRect:CGRectMake(0, 0, imageView.frame.size.width, imageView.frame.size.height)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(),kCGImageAlphaNone);    //kCGImageAlphaPremultipliedLast);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 10);
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 1, 0, 0, 10);
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), point.x, point.y);
//this line code for erasing select the part of the image
CGContextClearRect (UIGraphicsGetCurrentContext(), CGRectMake(point.x, point.y, 30, 30)); 
//End the code
CGContextStrokePath(UIGraphicsGetCurrentContext());
imageView.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();


Have you tried just using [imageView removeFromSuperview]?


If you are trying to remove all subviews for some reason, you can try:

for (UIView *view in imageView.subviews) {
    [view removeFromSuperview];
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号