2011-05-15 29 views
0

我有3個UIImageViews我想加載一個圖像。 對於1張圖片,這不是一個問題,但我該如何縮放到3?下面的代碼是我現在所擁有的。多個UIImageViews與UIImagePickers

-(IBAction) getPhoto:(id) sender { 
UIImagePickerController * picker = [[UIImagePickerController alloc] init]; 
    picker.delegate = self; 
    picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum; 
    [self presentModalViewController:picker animated:YES]; 

} 


- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { 
[picker dismissModalViewControllerAnimated:YES];  
UIImage* image = [info objectForKey:UIImagePickerControllerOriginalImage]; 
[my_image_1 setImage:image forState:UIControlStateNormal]; 

} 
+0

要加載在同一圖像所有3個'UIImageView's?如果是這樣,那麼只需爲所有圖像視圖執行'setImage:forState:',而不僅僅是第一個。 – 2011-05-15 13:25:08

+0

我想加載3個不同的圖像。所以3個按鈕來加載圖像。 - ErikS – ErikS 2011-05-15 19:41:27

回答

1

你有沒有看着thisthis?他們似乎指着這個resource

編輯

基於您的評論,我建議你在你的類中聲明伊娃imageViewToSet和改變你在下面的問題的方法,

-(IBAction) getPhoto:(id) sender { 
    // Add code to identify the sender(button) via tags or outlets and set imageViewToSet to the mapped imageView through a switch or if statement. 
    UIImagePickerController * picker = [[UIImagePickerController alloc] init]; 
    picker.delegate = self; 
    picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum; 
    [self presentModalViewController:picker animated:YES]; 
} 


- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { 
    [picker dismissModalViewControllerAnimated:YES];  
    imageViewToSet.image = [info objectForKey:UIImagePickerControllerOriginalImage]; 
} 
+0

我確實遇到過這些鏈接。我不想同時選擇多個圖像。在ViewController中,我有3個圖像和3個按鈕來選擇圖像。我可以以某種方式將'發件人'傳遞給imagePickerController嗎? – ErikS 2011-05-15 20:01:16

+0

根據您的評論添加了修改。這是否符合你的需求? – 2011-05-15 20:17:47

+0

謝謝Deepak,它工作。 – ErikS 2011-05-16 21:45:55

相關問題