I need to make UIImageView transparent at the Middle Position(Round Circle ..See attached image)
I should be able to see the Behind Subviews of UIImageView via that middle circle...i tried CAShapeLayer..but i am not able to see the behind subviews of UIImageView..Please help me..Sorry for my English....
CAShapeLayer *circleLayer = [CAShapeLayer layer];
// Give the layer the same bounds as your image view
[circleLayer setBounds:CGRectMake(100.0f, 100.0f, [((UIImageView *)view) bounds].size.width,
[((UIImageView *)view) bounds].size.height)];
// Position the circle anywhere you like, but this will center it
// In the parent layer, which will be your image view's root layer
[circleLayer setPosition:CGPointMake(100,
100)];
// Create a circle path.
UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:
CGRectMake(100.0f, 100.0f, 50.0f, 50.0f)];
// Set the path on the layer
[circleLayer setPath:[path CGPath]];
// Set the stroke color
[circleLayer setStrokeColor:[[UIColor redColor] CGColor]];
// Set the stroke line width
[circleLayer setLineWidth:2.0f];
// Add the sublayer to the image view's layer tree
[circleLayer setOpacity:0.5];
[[((UIImageView *)view) layer] addSublayer:circleLayer];
一种方法是这样的。我有一个包含主图像的图像视图,以及另一个名为 BlackCircle 的图像,它只是一个 40x40 的黑色圆圈(我在 Pixen 应用程序中制作的)。该操作方法使主图像在与黑色圆圈重叠的地方变得透明,我将其放置在主图像的中心:
@interface ViewController ()
@property (weak,nonatomic) IBOutlet UIImageView *imageView;
@end
@implementation ViewController
-(void)viewDidLoad {
[super viewDidLoad];
self.imageView.image = [UIImage imageNamed:@"House.tiff"];
self.imageView.backgroundColor = [UIColor clearColor];
}
-(IBAction)createAlphaClippedImage:(id)sender {
UIImage *circleImage = [UIImage imageNamed:@"BlackCircle.png"];
UIImage *mainImage = [UIImage imageNamed:@"House.tiff"];
UIGraphicsBeginImageContextWithOptions(mainImage.size, NO, 0.0);
CGRect imageRect = CGRectMake(0.0f, 0.0f, mainImage.size.width, mainImage.size.height);
CGRect centerCircleRect = CGRectMake(mainImage.size.width/2.0 - circleImage.size.width/2.0, mainImage.size.height/2.0 - circleImage.size.height/2.0,circleImage.size.width,circleImage.size.height);
[mainImage drawInRect:imageRect];
[circleImage drawInRect:centerCircleRect blendMode:kCGBlendModeXOR alpha:1.0];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
self.imageView.image = image;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)