iOS - 指定UIView的某几个角为圆角
ios 指定 几个 圆角 uiview
2023-09-11 14:21:34 时间
如果需要将UIView的4个角全部都为圆角,做法相当简单,只需设置其Layer的cornerRadius属性即可(项目需要使用QuartzCore框架)。而若要指定某几个角(小于4)为圆角而别的不变时,这种方法就不好用了。
对于这种情况,Stackoverflow上提供了几种解决方案。其中最简单优雅的方案,就是使用UIBezierPath。下面给出一段示例代码。
/* 指定UIView的某几个角为圆角 * UIRectCornerTopLeft * UIRectCornerTopRight * UIRectCornerBottomLeft * UIRectCornerBottomRight * UIRectCornerAllCorners */ UIView *view = [[UIView alloc] initWithFrame:CGRectMake(120, 120, 80, 80)]; view.backgroundColor = [UIColor redColor]; [self.view addSubview:view]; UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:view.bounds byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii:CGSizeMake(10, 10)]; CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init]; maskLayer.frame = view.bounds; maskLayer.path = maskPath.CGPath; view.layer.mask = maskLayer;
相关文章
- iOS真机调试 for Xcode 5
- iOS开发UI篇—常见的项目文件介绍
- 【IOS-COCOS2D游戏开发之十】添加粒子系统特效并解决粒子特效与LAYER之间的坐标问题;
- 【转】【UNITY3D 游戏开发之十】关于IL2CPP(支持IOS-64BIT)的深入讲解以及UNITY优化方面的几篇文章
- iOS开发那些事-iOS网络编程同步GET方法请求编程
- ios swift5 UIlabel 根据文字(内容)计算高度 宽度确定,高度自适应,但要提前知道高度 boundingRectWithSize
- iOS 小组件 widget 编辑小组件
- ios swift 5 UIView切圆角,指定某几个角,2个,左上,左下,右上,右下
- iOS swift 设置电量 计算属性实例
- ios自定义相机AVCaptureSession
- ios蓝牙扫描指定的设备scanForPeripheralsWithServices(过滤掉其他设备,只留下自家设备)
- ios返回到指定控制器oc
- iOS依据字符串计算UITextView高度
- iOS配置Dot和Doh