我已經使用Imagepickerview控制器來選擇照片並使用imageview在uiview中顯示它,但我的問題是使用imageview只有一個圖像可以顯示兩個。 它繼續取代現有的,如果我選擇第二個。請給出一些建議如何顯示兩張照片。如何使用imageview在iphone中顯示相冊照片
here is my source code.
-(void) ViewDidLoad
{
attachPhotoBtn = [UIButton buttonWithType:UIButtonTypeCustom];
attachPhotoBtn.frame = CGRectMake(400, 125, 44, 44);
UIImage *attachImg = [UIImage imageNamed:@"album_add_off.png"];
[attachPhotoBtn setImage:attachImg forState:UIControlStateNormal];
[attachPhotoBtn addTarget:self action:@selector(attachPhoto:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:attachPhotoBtn];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
imageView = [[UIImageView alloc] initWithFrame:CGRectMake(50, 125, 64, 52)];
// imageView.backgroundColor = [UIColor greenColor];
[self.view addSubview:imageView];
}
}
- (IBAction)attachPhoto:(id)sender {
[sender setImage:[UIImage imageNamed:@"album_add.png"] forState:UIControlStateNormal];
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeSavedPhotosAlbum])
{
UIImagePickerController *imagePicker =[[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.mediaTypes = [NSArray arrayWithObjects:(NSString *) kUTTypeImage,(NSString *)kUTTypeVideo,nil];
imagePicker.allowsEditing = NO;
// On iPad use pop-overs.
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
_popover = [[UIPopoverController alloc] initWithContentViewController:imagePicker];
[_popover presentPopoverFromRect:attachPhotoBtn.frame
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionUp
animated:YES];
}
}
else
{
// On iPhone use full screen presentation.
// [[self presentingViewController] presentViewController:imagePicker animated:YES completion:nil];
}
newMedia = NO;
}
#pragma mark Image picker controller delegate methods
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
// [self dismissModalViewControllerAnimated:YES];
if ([mediaType isEqualToString:(NSString *)kUTTypeImage]) {
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
imageView.image = image;
[picker dismissViewControllerAnimated:NO completion:nil];
}
粘貼實際的代碼。帶有大寫字母「V」的ViewDidLoad並不真實。 – 2013-02-05 06:58:47
通過這篇文章 - http://stackoverflow.com/questions/1291270/select-multiple-images-uiimagepickercontroller-or-photos-app-share-ui –
替換此行imageView.image = image;到[imageView setImage:image];試試這個,並告訴我它的工作與否:) – Rushabh