开发者

create UIImage from UILabel?

开发者 https://www.devze.com 2023-04-11 13:54 出处:网络
I can use the following code to create image from UIView. However the same code won\'t capture the text of UILabel.(it captures label\'s background color though)

I can use the following code to create image from UIView.

However the same code won't capture the text of UILabel.(it captures label's background color though) How can I create image of UILabel with text?

CGSize size = view.bounds.size;
CGContextRef context = CreateARGBBitmapContext(size);
CGContextTranslateCTM(context, 0,开发者_C百科 size.height);
CGContextScaleCTM(context, 1.0, -1.0);
[view.layer renderInContext: context];
CGImageRef imageRef = CGBitmapContextCreateImage(context);
UIImage* img = [UIImage imageWithCGImage: imageRef];
CGImageRelease(imageRef);
CGContextRelease(context);


In the viewcontroller, select the label and on the right side, you should be able to set an image to the label. Also, you might be having a problem with layers... [self addChild: label z:0 tag:1]; Just in case you don't know, z:0 means the layer. So something with z:-1 would be below a picture with z:0. You could just set the text ontop of the label

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号