Use [myLabel.layer renderInContext:UIGraphicsGetCurrentContext()];
在当前上下文中绘制。
For eg:-
UIGraphicsBeginImageContextWithOptions(newImageSize, NO, 0.0); //retina res
[self.viewForImg.layer renderInContext:UIGraphicsGetCurrentContext()];
[myLabel.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
根据您的评论,如果您想在特定框架中绘制它,请按如下方式操作,
[myLabel drawTextInRect:CGRectMake(0.0f, 0.0f, 100.0f, 50.0f)];
如果你想给背景上色,试试这个,
CGRect drawRect = CGRectMake(rect.origin.x, rect.origin.y,rect.size.width, rect.size.height);
CGContextSetRGBFillColor(context, 100.0f/255.0f, 100.0f/255.0f, 100.0f/255.0f, 1.0f);
CGContextFillRect(context, drawRect);
或者你可以检查这个问题设置CGContext透明背景 https://stackoverflow.com/questions/2125543/setting-a-cgcontext-transparent-background.