iOS笔记之使用贝塞尔曲线给View/Layer添加圆角
1、添加左上、右下圆角
UIView *redView = [[UIView alloc] initWithFrame:CGRectMake(10, 80, 150, 70)];
redView.backgroundColor = [UIColor redColor];
[self.view addSubview:redView];
//添加圆角
UIBezierPath *cornerPath = [UIBezierPath bezierPathWithRoundedRect:redView.bounds byRoundingCorners:(UIRectCornerTopLeft|UIRectCornerBottomRight) cornerRadii:CGSizeMake(35, 35)];
CAShapeLayer *maskLayer = [CAShapeLayer layer];
maskLayer.frame = redView.bounds;
maskLayer.path = cornerPath.CGPath;
redView.layer.mask = maskLayer;
2、添加右上、左下圆角
UIView *greenView = [[UIView alloc] initWithFrame:CGRectMake(10, 200, 150, 70)];
greenView.backgroundColor = [UIColor greenColor];
[self.view addSubview:greenView];
//添加圆角
UIBezierPath *cornerPath1 = [UIBezierPath bezierPathWithRoundedRect:greenView.bounds byRoundingCorners:(UIRectCornerTopRight|UIRectCornerBottomLeft) cornerRadii:CGSizeMake(35, 35)];
CAShapeLayer *maskLayer1 = [CAShapeLayer layer];
maskLayer1.frame = greenView.bounds;
maskLayer1.path = cornerPath1.CGPath;
greenView.layer.mask = maskLayer1;
3、使View成为圆(如:用户的头像)
UIView *circleView = [[UIView alloc] initWithFrame:CGRectMake(200, 150, 100, 100)];
circleView.backgroundColor = [UIColor orangeColor];
[self.view addSubview:circleView];
//添加圆角
UIBezierPath *circlePath = [UIBezierPath bezierPathWithRoundedRect:circleView.bounds byRoundingCorners:(UIRectCornerTopLeft|UIRectCornerBottomRight|UIRectCornerTopRight|UIRectCornerBottomLeft) cornerRadii:CGSizeMake(50, 50)];
CAShapeLayer *circleLayer = [CAShapeLayer layer];
circleLayer.frame = circleView.bounds;
circleLayer.path = circlePath.CGPath;
circleView.layer.mask = circleLayer;
效果图如下
文章图片
image.png
推荐阅读
- iOS|iOS ipad和iphone兼容~demo
- flutter系列之:flutter中常用的container layout详解
- flutter系列之:flutter中常用的container|flutter系列之:flutter中常用的container layout详解
- 薛之谦(“所以请你同意,我回去拿个行李”)
- 虽曰爱之,其实害之。
- 商学院——《沙漠风云》之第一回|商学院——《沙漠风云》之第一回 大小穿越、商战前传,各路精英、蓄势待发
- Verilog|(127)Verilog HDL(设计一个优先编码器之Always case2)
- Verilog|(128)Verilog HDL(设计一个优先编码器之Always casez)
- 钛极客|苹果折叠屏没等来,华硕先将OLED折叠屏引入笔记本领域 | 科技前线
- 盘点云顶第三赛季的那些亮点!或是自走棋界的巅峰之作!