gpt4 book ai didi

ios - 如何用另一个 UIView 的矩形切割 UIView 的顶角

转载 作者:行者123 更新时间:2023-11-29 11:32:50 24 4
gpt4 key购买 nike

如何在特定点切割另一个 View 的矩形 View ?

Required Result

这是两个 View

  1. 显示图像的 UIImageView。
  2. 具有显示用户状态的背景颜色的 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];

}

enter image description here向图层添加蒙版。

关于ios - 如何用另一个 UIView 的矩形切割 UIView 的顶角,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51907423/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com