如何在特定点切割另一个 View 的矩形 View ?
这是两个 View
- 显示图像的 UIImageView。
- 具有显示用户状态的背景颜色的 UIView。
注意:两个 View 的高度和宽度都是统一的。
一个工作示例会非常有帮助。
谢谢
最佳答案
例子:
-(void) viewDidAppear:(BOOL)animated {
self.view.backgroundColor = [UIColor blueColor];
UIImageView* yourView = [[UIImageView alloc] initWithFrame:CGRectMake(200, 200, 200, 200)];
yourView.center = self.view.center;
yourView.image = [UIImage imageNamed:@"testImg"];
yourView.layer.cornerRadius = 100;
yourView.clipsToBounds = YES;
[self.view addSubview: yourView];
NSUInteger radius = 50;
UIBezierPath *circlePath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, 2.0*radius, 2.0*radius) cornerRadius:radius];
UIBezierPath *path = [UIBezierPath bezierPathWithRect:yourView];
[path appendPath:circlePath];
CAShapeLayer *maskLayer = [CAShapeLayer layer];
maskLayer.path = path.CGPath;
maskLayer.fillRule = kCAFillRuleEvenOdd;
yourView.layer.mask = maskLayer;
UIImageView* smallView = [[UIImageView alloc] initWithFrame:CGRectMake(yourView.frame.origin.x + 8 ,
yourView.frame.origin.y + 8 , 80, 80)];
smallView.image = [UIImage imageNamed:@"testImg"];
smallView.layer.cornerRadius = 40;
smallView.clipsToBounds = YES;
[self.view addSubview:smallView];
}
关于ios - 如何用另一个 UIView 的矩形切割 UIView 的顶角,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51907423/