Нет, не все так просто. CGRect является структурой и не поддерживает наследование (например, CGEllipse
, CGTriangle
и т. Д.)
Однако вы можете сделать следующее:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIImageView *imageView = [[UIImageView alloc] initWithFrame:self.view.frame];
imageView.image = [UIImage imageNamed:@"stack-overflow.jpg"];
[self.view addSubview:imageView];
CGMutablePathRef path = CGPathCreateMutable();
CGPathAddEllipseInRect(path, NULL, imageView.bounds);
CAShapeLayer *shapeLayer = [[CAShapeLayer alloc] initWithLayer:imageView.layer];
shapeLayer.path = path;
[imageView.layer setMask:shapeLayer];
}
Если вы включите <QuartzCore/QuartzCore.h>
в свой проект и сделаете ссылку на QuartzCore.framework
.
Для получения дополнительной информации о CGMutablePathRef
, проверьте здесь