合并uilabel和uiimageview [英] merging uilabel and uiimageview
问题描述
我从相册中选取了一张图片,并将其放在名为imageView的UIImageView
中
然后,我在图像上添加了一些文本,使用UITextView
作为输入源,并在uiimageview顶部使用UILabel
来显示文本.
I picked an image from the photo album and put it in an UIImageView
called imageView
I then added some text over the image using UITextView
as source of input and a UILabel
on top of the uiimageview to display the text.
到目前为止一切都很好.
So far so good.
现在,我正在尝试将标签和imageview合并,以执行其他操作,但是我无法使其正常工作.我已经尝试过针对类似问题的一些解决方案,但它们对我不起作用.
Now I'm trying to merge the label and the imageview in order to do other stuff with that but I 'm not getting it to work. I have tried some solutions given to similar questions but they didn't work for me.
我尝试过
UIGraphicsBeginImageContextWithOptions(_imageView.bounds.size, NO, 0.0); //retina res
[self.imageView.layer renderInContext:UIGraphicsGetCurrentContext()];
[_displaylabel.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
它告诉我接收到的类型例如消息的CAlayer
是前向声明".
it tells me that Received type "CAlayer
for instance message is a forward declaration".
还有其他建议吗?
推荐答案
UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"background.png"]];
UIView *tempView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, imgView.frame.size.width, imgView.frame.size.height)];
[tempView addSubview:imgView];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(tempView.frame.size.width/2, 0, 200, tempView.frame.size.height/2)];
[label setText:@"Hello... You there"];
[label setTextColor:[UIColor blackColor]];
[label setTextAlignment:NSTextAlignmentLeft];
[label setBackgroundColor:[UIColor clearColor]];
[tempView addSubview:label];
UIGraphicsBeginImageContext(tempView.bounds.size);
[tempView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *finalImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
这篇关于合并uilabel和uiimageview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!