I have the following code:
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSaveGState(context);
CALayer *sublayer = [CALayer layer];
sublayer.backgroundColor = [UIColor orangeColor].CGColor;
sublayer.cornerRadius = 20.0;
sublayer.frame = CGRectMake(20, 0, 300, 20);
[sublayer setNeedsDisplay];
[sublayer drawInContext:context];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
但是当我查看返回的新图像时,只有一个空图像。当我将drawInContext更改为renderInContext时,我得到了上面的子层,但似乎坐标系混乱了。
有任何想法为什么上述的drawInContext没有起作用?