将UIButton粘贴到UIImageView的UIImage中

时间:2012-04-22 11:33:25

标签: iphone ios xcode

我有一个带有UIButton的UIImageView,我希望能够将其作为带有电子邮件的图像发送,但是当我从UIImageView中取出图像时,UIImageView中的UIButton不会被UIImageView的图像“粘住”。

有什么建议吗?

提前致谢。

1 个答案:

答案 0 :(得分:1)

您可以使用以下代码添加UIButton和UIImageView并获取所需的屏幕截图图像。  您可能需要将QuartzCore.framework添加到项目和#import

使用其他UI元素获取图像。

UIGraphicsBeginImageContext(CGSizeMake(320, 480)); // Here provide width and height of UIImageView
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];//Here use required view 
UIImage *outputImage = UIGraphicsGetImageFromCurrentImageContext();//outputImage is your required image
UIGraphicsEndImageContext();

显示图像

UIImageView * screenShotView = [[UIImageView alloc] initWithImage:outputImage];
[screenShotView setFrame:CGRectMake(0, 0, 320, 480)];
[self.view addSubview:screenShotView];