ios - 如何用另一个 UIView 的矩形切割 UIView 的顶角
问题描述
如何在特定点用另一个视图的矩形切割视图?
这是两种观点
- UIImageView 显示图像。
- UIView 具有显示用户状态的背景颜色。
注意:两个视图的高度和宽度都是统一的。
一个工作示例将非常有帮助。
谢谢
解决方案
例子:
-(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];
}
推荐阅读
- javascript - 如何获取元素已经“显示”并且不需要在列表中滚动的信息(el.scoolingIntoView)?
- docker - 运行容器时找不到文件错误
- c++ - 如何确保 range1 小于 range2?
- python - 为什么我不能从动态网页中抓取表格
- firebase - 如何在 Firestore Flutter 中按字段内容对文档进行排序
- typescript - 为什么我们在处理 vue 组件时会丢失 typescript 类型检查?
- reactjs - react-phone-input-2 与 react-hook-form
- css - CSS文件在服务器端JSX中抛出错误
- flutter - 面临多手势检测的问题 - Flutter
- sqlite - 如何在golang中查询到sqlite3?