iOS开发之指定UIView的某几个角为圆角
2016-04-20 12:19
573 查看
如果需要将UIView的4个角全部都为圆角,做法相当简单,只需设置其Layer的cornerRadius属性即可(项目需要使用QuartzCore框架)。而若要指定某几个角(小于4)为圆角而别的不变时,这种方法就不好用了。
一种简单的实现方式 ,用到CAShapeLayer
UIView *redView = [[UIView
alloc] initWithFrame:CGRectMake(120,
300, 80,
80)];
redView.backgroundColor = [UIColor
redColor];
[self.view
addSubview:redView];
UIBezierPath *maskPath = [UIBezierPath
bezierPathWithRoundedRect:redView.bounds
byRoundingCorners:UIRectCornerBottomLeft |
UIRectCornerBottomRight cornerRadii:CGSizeMake(10,
10)];
// [UIBezierPath bezierPathWithRoundedRect:<#(CGRect)#> byRoundingCorners:<#(UIRectCorner)#> cornerRadii:<#(CGSize)#>]
// typedef NS_OPTIONS(NSUInteger, UIRectCorner) {
// UIRectCornerTopLeft = 1 << 0,
// UIRectCornerTopRight = 1 << 1,
// UIRectCornerBottomLeft = 1 << 2,
// UIRectCornerBottomRight = 1 << 3,
// UIRectCornerAllCorners = ~0UL
// };可以选择任意几个角
// cornerRadii 圆角的大小
CAShapeLayer *maskLayer = [[CAShapeLayer
alloc] init];
maskLayer.frame = redView.bounds;
maskLayer.path = maskPath.CGPath;
redView.layer.mask = maskLayer;
一种简单的实现方式 ,用到CAShapeLayer
UIView *redView = [[UIView
alloc] initWithFrame:CGRectMake(120,
300, 80,
80)];
redView.backgroundColor = [UIColor
redColor];
[self.view
addSubview:redView];
UIBezierPath *maskPath = [UIBezierPath
bezierPathWithRoundedRect:redView.bounds
byRoundingCorners:UIRectCornerBottomLeft |
UIRectCornerBottomRight cornerRadii:CGSizeMake(10,
10)];
// [UIBezierPath bezierPathWithRoundedRect:<#(CGRect)#> byRoundingCorners:<#(UIRectCorner)#> cornerRadii:<#(CGSize)#>]
// typedef NS_OPTIONS(NSUInteger, UIRectCorner) {
// UIRectCornerTopLeft = 1 << 0,
// UIRectCornerTopRight = 1 << 1,
// UIRectCornerBottomLeft = 1 << 2,
// UIRectCornerBottomRight = 1 << 3,
// UIRectCornerAllCorners = ~0UL
// };可以选择任意几个角
// cornerRadii 圆角的大小
CAShapeLayer *maskLayer = [[CAShapeLayer
alloc] init];
maskLayer.frame = redView.bounds;
maskLayer.path = maskPath.CGPath;
redView.layer.mask = maskLayer;
相关文章推荐
- 队列Queue 先进先出 栈Stack 先进后出
- UIBezierPath贝塞尔弧线常用方法记
- LeetCode 52. N-Queens II
- rocketmq问题汇总-如何将特定消息发送至特定queue,消费者从特定queue消费
- iOS开发之UIView的生命周期是什么样的?
- Google Protobuf Guide
- com.android.build.transform.api.TransformException
- 算法Sedgewick第四版-第1章基础-024-M/M/1 queue
- HDU4027(Can you answer these queries?)
- 自定义UITableViewCell的两种方式
- iOS开发调整UILabel的行间距
- 【UE4学习】06——蓝图常用函数
- 算法Sedgewick第四版-第1章基础-022一QueueWithTwoStacks
- 编译原理:用bison实现huiwen.y和huiwen.lex判断是否为回文
- java序列化和serialVersionUID
- String、stringbuffer与stringbuilder的区别
- UGUI实现的虚拟摇杆,可改变摇杆位置
- BlockingQueue的使用
- [Form Builder]POST 与 commit_form 的区别
- iOS7之后,关于NavigationBar存在时,UIScrollView内容发生偏移的问题