iOS 设置圆角的一点小技巧

2016-06-29  本文已影响173人  Supersweet007

比如你在设置圆角的时候

当shouldRasterize设成true时,layer被渲染成一个bitmap,并缓存起来,等下次使用时不会再重新去渲染了。实现圆角本身就是在做颜色混合(blending),如果每次页面出来时都blending,消耗太大,这时shouldRasterize = yes,下次就只是简单的从渲染引擎的cache里读取那张bitmap,节约系统资源。

额外收获:如果在滚动tableView时,每次都执行圆角设置,肯定会阻塞UI,设置这个将会使滑动更加流畅。

这个是我使用的

self.ktghLabel.layer.masksToBounds = YES;

self.ktghLabel.layer.cornerRadius = 5.0f;

//

self.ktghLabel.layer.shouldRasterize = YES;

self.ktghLabel.layer.rasterizationScale = [UIScreen mainScreen].scale;

self.layer.shouldRasterize = YES;self.layer.rasterizationScale = [UIScreen mainScreen].scale;CGPathRef path = [UIBezierPath bezierPathWithRect:self.bounds].CGPath;[self.layer setShadowPath:path];

这个是我在网上找的方便以后优化代码

上一篇 下一篇

猜你喜欢

热点阅读