美文网首页
图片设置圆角

图片设置圆角

作者: sfandy | 来源:发表于2016-11-25 15:13 被阅读33次

关于给图片设置圆角,普遍使用layer进行处理,简单方便;
但过多的渲染layer会导致降低app性能,拖慢了fps(特别是在cell中容易发觉)。

建议通过渲染画布的方式实现:

分类:
@implementation UIImage (RoundedCorner)

 - (UIImage *)imageWithRoundedCornersAndSize:(CGSize)sizeToFit a ndCornerRadius:(CGFloat)radius {
     CGRect rect = (CGRect){0.f, 0.f, sizeToFit};
     UIGraphicsBeginImageContextWithOptions(sizeToFit, NO, UIScr een.mainScreen.scale);
     CGContextAddPath(UIGraphicsGetCurrentContext(),      
     [UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:radius].CGPath);     
     CGContextClip(UIGraphicsGetCurrentContext());
     [self drawInRect:rect];
     UIImage *output = UIGraphicsGetImageFromCurrentImageContext ();
     return output
}

- (void)drawRect:(CGRect)rect {
    CGRect bounds = self.bounds;      
   [[UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:8.0] addClip];[self.image drawInRect:bounds];
}
 
@end

相关文章

  • 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/djxwpttx.html