增加view的圆角笔记

   iOS开发中,常常由于需求,而需要圆角的样式.如果4个角都是圆角的,还好说.一行两行代码就可以搞定.就是CAlayer.可是现在我想说下不规则的圆角.目前我还没有找到更好的方法来画圆角.希望有解决方法的朋友看到这篇文章,能交流学习下.

copycode.gif

1     UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:sourceView.bounds byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerTopLeft cornerRadii:CGSizeMake(5, 5)];

2     CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];

3     maskLayer.frame = sourceView.bounds;

4     maskLayer.path = maskPath.CGPath;

5     sourceView.layer.mask = maskLayer;

号称是最优雅的画不定圆角视图的方法.想画哪个圆角就在bezierPathWithRoundedRect:byRoundingCorners: 方法中添加相应枚举值就行了.如下图(左侧图标的左圆角就是用这种方法切的.):

posted @ 2015-03-04 17:09  深山一枯柴  阅读(124)  评论(0编辑  收藏  举报