- 最简单的方式就是要美工妹子给你给你切一张带圆角的图片,用iimageNamed:@""加载图片。
- 通过图层layer实现,不过如果是tableView上面多处用到了图片圆角 使用layer会造成离屏渲染,会加大GPU的开销,在性能上会大大折扣,不建议使用。
self.imageView.layer.masksToBounds = yes;
self.imageView.layer.cornerRadius = 10;
- 通过QuartzCore实现:
-(UIImage*) circleImage:(UIImage*) image withParam:(CGFloat) inset {
UIGraphicsBeginImageContext(image.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(context, 2);
CGContextSetStrokeColorWithColor(context, [UIColor redColor].CGColor);
CGRect rect = CGRectMake(inset, inset, image.size.width - inset * 2.0f, image.size.height - inset * 2.0f);
CGContextAddEllipseInRect(context, rect);
CGContextClip(context);
[image drawInRect:rect];
CGContextAddEllipseInRect(context, rect);
CGContextStrokePath(context);
UIImage *newimg = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newimg;
}
- 利用贝塞尔曲线画出来
self.imgView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 40, 40)];
UIImage *image =[UIImage imageNamed:@"headerImage"];
UIGraphicsBeginImageContextWithOptions(self.imgView.bounds.size, NO, 1.0);
[[UIBezierPath bezierPathWithRoundedRect:self.imgView.bounds cornerRadius:self.imgView.bounds.size.width/2.0]addClip];
[image drawInRect:self.imgView.bounds];
self.imgView.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
网友评论