您的位置:首页 > 移动开发 > IOS开发

iOS切圆角

2015-11-27 18:23 337 查看
方法一、layer.cornerRadius

第一种方法最简单,通过层对象的cornerRadius属性实现圆角效果,代码如下:

view.layer.cornerRadius = 8.0;

view.layer.masksToBounds = YES;

缺点是会有2次rending passes。首先off-screen画出带圆角的图,然后在视图上画第二次。

方法二、通过UIBezierPath对象设置带圆角的作图区域

这种方法的好处是只有一次rending pass,是三种方法中效率最高的。缺点是需要override视图。代码如下:

- (void)drawRect:(CGRect)rect {

CGRect bounds = self.bounds;

[[UIColor whiteColor] set];

UIRectFill(bounds);

[[UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:8.0] addClip];

[self.image drawInRect:bounds];

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: