iOS开发之指定UIView的某几个角为圆角
2016-01-18 21:24
561 查看
如果需要将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/
相关文章推荐
- REG QUERY命令参数(注册表)
- hdu 1387 Team Queue (链表)
- [问题记录]AutoLayout下UIScrollView 布局错位及解决方法
- java基础学习总结——GUI编程(一)
- java基础学习总结——GUI编程(二)
- UGUI中ScrollView滑动适应问题解决办法
- Android java.exe finished with non-zero exit value 1
- serialVersionUID的作用
- Uncaught InvalidStateError: Failed to set the 'value' property on 'HTMLInputElement': This input element accepts a filename, which may only be programmatically set to the empty string.
- Git---通过一个具体实例详解Git常用命令以及提交pr(pull request)
- LeetCode题解——Longest Consecutive Sequence
- LeetCode Permutation Sequence
- UI课程(tableView)
- UVA 11404 Palindromic Subsequence 刘汝佳的动归练习
- jd-gui报错INTERNAL ERROR 解决办法
- hdu 1159 Common Subsequence 最大公共子串
- hdu1423 Greatest Common Increasing Subsequence
- 【Elasticsearch】query_string的各种用法
- UI控件ViewPager浅析
- 关于DelayQueue的一些