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

标签 ios objective-c iphone

如何在特定点切割另一个 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/

相关文章:

ios - 在 iOS 10 中使用远程通知(富媒体推送通知)在通知栏中显示图像

iphone - 在我的主视图中将 UIImageView 置于其他 UIImageView 之上

ios - 如何在 iOS 中裁剪视频

iphone - 是否可以获取iOS内置控件中使用的 Assets ?

iphone - 保存图像供以后在 iPhone 中使用

objective-c - 如何检查 objective-c 对象?

iphone - 正确使用 transitionFromViewController :toViewController:duration:options:animations:completion:

iphone - 在 iPad 中创建交互式视频 - 用于产品演示的应用程序

ios - 将 iOS 升级到 13.3.1 后,Flutter 应用程序无法在 iPhone 中运行

iphone - 从海外调用美国电话的最佳方式?