What about the renderInContext CALayer method?
-(void)methodName:(CGContextRef)ctx { UIView *someView = [[UIView alloc] init]; [someView.layer renderInContext:ctx]; }
EDIT: As noted in the comment, due to the difference in origin in the two coordinate systems involved in the process, the layer will be flipped. To compensate, you just need to flip the context vertically. This is technically performed with a scale and transform transformation that can be combined into a single matrix transformation:
-(void)methodName:(CGContextRef)ctx { UIView *someView = [[UIView alloc] init]; CGAffineTransform verticalFlip = CGAffineTransformMake(1, 0, 0, -1, 0, someView.frame.size.height); CGContextConcatCTM(ctx, verticalFlip); [someView.layer renderInContext:ctx]; }
Matt wilding
source share