iOS 设置圆角

方式一:

self.layer.cornerRadius = 10.0f;

self.layer.masksToBounds = YES;

self.layer.shouldRasterize = YES; //圆角缓存

self.layer.rasterizationScale = [UIScreen mainScreen].scale;//提高流畅度

经测试 加上后两句之后流畅度有了提高。

方式二:

可以给UIImage添加一个分类UIImage+Extension,返回圆形图片

- (UIImage *)createCornerImage{

// 开始图形上下文

UIGraphicsBeginImageContextWithOptions(self.size, NO, 0.0);

// 获得图形上下文

CGContextRef ctx = UIGraphicsGetCurrentContext();

// 设置一个范围

CGRect rect = CGRectMake(0, 0, self.size.width, self.size.height);

// 根据一个rect创建一个椭圆

CGContextAddEllipseInRect(ctx, rect);

// 裁剪

CGContextClip(ctx);

// 将原照片画到图形上下文

[self drawInRect:rect];

// 从上下文上获取剪裁后的照片

UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();

// 关闭上下文

UIGraphicsEndImageContext();

return newImage;

}

你可能感兴趣的:(iOS 设置圆角)