如果需要将UIView的4个角全部都为圆角,做法相当简单,只需设置其Layer的cornerRadius属性即可
2016-04-11 16:24
656 查看
如果需要将UIView的4个角全部都为圆角,做法相当简单,只需设置其Layer的cornerRadius属性即可(项目需要使用QuartzCore框架)。而若要指定某几个角(小于4)为圆角而别的不变时,这种方法就不好用了。
对于这种情况,Stackoverflow上提供了几种解决方案。其中最简单优雅的方案,就是使用UIBezierPath。下面给出一段示例代码。
其中,
指定了需要成为圆角的角。该参数是UIRectCorner类型的,可选的值有:
从名字很容易看出来代表的意思,使用“|”来组合就好了。
感谢原作者简明扼要的总结!
原文地址:http://webfrogs.me/2013/05/22/ios-view-assign-corner-radius/
对于这种情况,Stackoverflow上提供了几种解决方案。其中最简单优雅的方案,就是使用UIBezierPath。下面给出一段示例代码。
UIView *view2 = [[UIView alloc] initWithFrame:CGRectMake(120, 10, 80, 80)]; view2.backgroundColor = [UIColor redColor]; [self.view addSubview:view2]; UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:view2.bounds byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii:CGSizeMake(10, 10)]; CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init]; maskLayer.frame = view2.bounds; maskLayer.path = maskPath.CGPath; view2.layer.mask = maskLayer;
其中,
byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight
指定了需要成为圆角的角。该参数是UIRectCorner类型的,可选的值有:
* UIRectCornerTopLeft * UIRectCornerTopRight * UIRectCornerBottomLeft * UIRectCornerBottomRight * UIRectCornerAllCorners
从名字很容易看出来代表的意思,使用“|”来组合就好了。
感谢原作者简明扼要的总结!
原文地址:http://webfrogs.me/2013/05/22/ios-view-assign-corner-radius/
相关文章推荐
- 在海思hi3520上移植minigui3.0
- Spark Streaming + Flume Integration Guide
- iosUILabel高度自适应
- UIView和CALayer的区别 说的比较清楚了
- 警告:receiver Exported receiver does not require permission
- HDU - 4198 Quick out of the Harbour (BFS+优先队列)
- HDU 3836 —— Equivalent Sets
- Kafka源码分析之InFlightRequests
- UILabel设置行距和每段初始距离
- iOS开发之UITabBarController和UICollectionView的使用
- iOS 请求数据或者上传头像的时候卡UI界面
- UIImageView实现图片平铺
- HDOJ 2767 Proving Equivalences
- java中queue的使用
- Access restriction: The type 'BASE64Encoder' is not API (restriction on required library 'D:\Java\jd
- WEB界面设计中太原UI设计师讲何为网格布局设计?
- iOS-UIImagePickerController 内存警告研究
- iOS学习笔记10-UIView动画
- windows下安装requests
- 改变UIView 的位置 Center和Frame