If there are several buttons in my cell, do I need to rasterize them individually, or will it be automatically considered?
No, shouldRaserize makes the layer and all sublayers rasterized. But I will be careful when using it, because every time it changes, your layer will be redrawn.
Check out this thread: UIView self.layer.shouldRasterize = YES and Performance Issues
Personally, I prefer to rasterize the layer that I need only once, during application startup. Here is a sample code on how to create your own separator for your cell:
@implementation UIImage (Extensions) + (UIImage *)imageFromLayer:(CALayer *)layer{ UIGraphicsBeginImageContext([layer frame].size); [layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *outputImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return outputImage; } @end @implementation CellSeparatorView static UIImage *patternLine; __attribute__((constructor)) static void initialize_cell_separator(){ @autoreleasepool { CAGradientLayer *gLayer = [CAGradientLayer layer]; gLayer.frame = CGRectMake(0, 0, 1, 2); gLayer.locations = @[@(0), @(0.5000), @(0.5001), @(1)]; gLayer.colors = @[(id)[RGB(241, 241, 241, 1) CGColor], (id)[RGB(241, 241, 241, 1) CGColor], (id)[RGB(250, 250, 250, 1) CGColor], (id)[RGB(250, 250, 250, 1) CGColor]]; gLayer.contentsScale = [[UIScreen mainScreen] scale]; gLayer.opaque = YES; dispatch_queue_t backgroundRenderQueue = dispatch_queue_create("backgroundRenderQueue", 0); dispatch_async(backgroundRenderQueue, ^{ patternLine = [[UIImage imageFromLayer:gLayer] retain]; }); } } __attribute__((destructor)) static void destroy_cell_separator(){ [patternLine release]; patternLine = nil; } - (id)initWithCoder:(NSCoder *)aDecoder{ if (self = [super initWithCoder:aDecoder]){ [self setBackgroundColor:[UIColor colorWithPatternImage:patternLine]]; self.opaque = YES; } return self; } @end
source share