2012-04-22 44 views
0

我有一個UIImageView與UIButton,我希望能夠作爲圖像發送電子郵件,但UIImageView中的UIButton不會與UIImageView的圖像「粘貼」,當我拿從UIImageView中映射出來。粘UIButton到UIImageView的UIImage

有什麼建議嗎?

在此先感謝。

+0

你是什麼意思 「stickied」 是什麼意思? – 2012-04-22 11:48:26

+0

我的意思是...我有一個UIImageView,我添加一個UIButton作爲UIImageView的子視圖。當我嘗試使用UIImageView.image時,我沒有得到我作爲UIImageView的子視圖添加的按鈕。 – WYS 2012-04-22 13:22:04

+0

哦,謝謝RIP,我會爲我所有的問題做到這一點:) – WYS 2012-04-22 13:23:44

回答

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]; 
+0

非常感謝,正是我所需要的! :) – WYS 2012-04-22 18:45:40