首页 > 其他 > 详细

圆角优化的处理

时间:2016-07-16 00:57:02      阅读:241      评论:0      收藏:0      [点我收藏+]

如何解决?

圆角使用UIImageView来处理。
简单来说,底层铺一个UIImageView,然后用GraphicsContext生成一张带圆角的图。

@implementation UIImage (RoundedCorner)

- (UIImage *)yal_imageWithRoundedCornersAndSize:(CGSize)sizeToFit andCornerRadius:(CGFloat)radius
{
    CGRect rect = (CGRect){0.f, 0.f, sizeToFit};

    UIGraphicsBeginImageContextWithOptions(sizeToFit, NO, UIScreen.mainScreen.scale);
    CGContextAddPath(UIGraphicsGetCurrentContext(),
                     [UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:radius].CGPath);
    CGContextClip(UIGraphicsGetCurrentContext());

    [self drawInRect:rect];
    UIImage *output = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    return output;
}

@end

这样,就可以避免在大量cell离屏渲染的时候拖慢fps。
当然,如果只是一两个view有圆角的需求,你大可不必这么折腾。直接设置layer.cornerRadius就可以了。

圆角优化的处理

原文:http://www.cnblogs.com/gyyxiaogao/p/5675028.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!