使用UIImagePickers的多个UIImageViews

时间:2011-05-15 10:48:13

标签: iphone uiimagepickercontroller

我有3个UIImageViews,我想加载图像。 对于1个图像,这不是问题,但如何缩放到3? 下面的代码就是我现在所拥有的。

-(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];

}

1 个答案:

答案 0 :(得分:1)

您是否查看了thisthis?他们似乎指向了这个resource

修改

根据您的评论,我建议您在班级中声明一个ivar 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];
}