码迷,mamicode.com
首页 > 其他好文 > 详细

圆角优化的处理

时间:2016-07-16 01:00:12      阅读:177      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!