美文网首页
图片设置圆角

图片设置圆角

作者: 橡树花香 | 来源:发表于2018-03-26 11:09 被阅读0次

1、不好的解决方案:使用下面的方式会强制Core Animation提前渲染屏幕的离屏绘制, 而离屏绘制就会给性能带来负面影响,会有卡顿的现象出现。
self.view.layer.cornerRadius = 5.0f;
self.view.layer.masksToBounds = YES;

2、正确的解决方案:使用绘图技术
(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;
}

3、还有一种方案:使用了贝塞尔曲线"切割"个这个图片, 给UIImageView 添加了的圆角,其实也是通过绘图技术来实现的。
/////eg:
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
imageView.center = CGPointMake(200, 300);
UIImage *anotherImage = [UIImage imageNamed:@"image"];
UIGraphicsBeginImageContextWithOptions(imageView.bounds.size, NO, 1.0);
[[UIBezierPath bezierPathWithRoundedRect:imageView.bounds
cornerRadius:50] addClip];
[anotherImage drawInRect:imageView.bounds];
imageView.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[self.view addSubview:imageView];

相关文章

  • Image

    直接圆角图片 设置圆角图片度数 设置圆角图片带灰色圆角边框 设置圆角图片带灰色圆角边框带阴影

  • iOS 图片添加阴影效果

    Code 圆形图片设置阴影(补充) < 设置图片圆角阴影

  • Flutter知识点总结一

    一、设置图片的圆角 由于图片不能直接设置圆角,所以我们需要采用其它方式来设置: 1、使用ClipRRect进行设置...

  • 实现圆角图片

    //设置圆角图片或者圆形图片 privateBitmapSettingBitmap(Bitmap bitmap) ...

  • 图片设置圆角

    1、不好的解决方案:使用下面的方式会强制Core Animation提前渲染屏幕的离屏绘制, 而离屏绘制就会给性能...

  • 设置图片圆角

  • 图片设置圆角

    关于给图片设置圆角,普遍使用layer进行处理,简单方便;但过多的渲染layer会导致降低app性能,拖慢了fps...

  • 图片圆角设置

    方案一:切layer# 直接设置该UIImageView的layer的cornerRadius属性(半径)为UII...

  • 设置圆角图片

    设置圆形图片(建议放到分类中使用)

  • 设置圆角图片

    开发中常常会需要将图片设置成圆角,下面就介绍3种实现方法: 第一种方法:通过设置layer的属性,实现圆角(这种方...

网友评论

      本文标题:图片设置圆角

      本文链接:https://www.haomeiwen.com/subject/lvnlcftx.html