方式1.(如果圆角视图比较少并且不复杂可以考虑使用)
// 通过view的layer图层进行剪切
self.nameLabel.layer.cornerRadius = 5;
self.nameLabel.layer.masksToBounds = YES;
方式2.(性能可能高点,通过画圆的方式获取image,然后再赋给视图)
/**
通过上下文实现画圆形图片方式
*/
- (UIImage *)circleImage
{
// NO代表透明
UIGraphicsBeginImageContextWithOptions(self.size, NO, 0.0);
// 获得上下文
CGContextRef ctx = UIGraphicsGetCurrentContext();
// 添加一个圆,此处是关键
CGRect rect = CGRectMake(0, 0, self.size.width, self.size.height);
CGContextAddEllipseInRect(ctx, rect);
// 裁剪
CGContextClip(ctx);
// 将图片画上去
[self drawInRect:rect];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
// 结束上下文
UIGraphicsEndImageContext();
return image;
}