原文地址:获取系统相册中图片的方法
[url]http://www.aisidachina.com/forum/viewthread.php?tid=244[/url]
定义一个按钮连接以下方法:
再调用以下委托:
[url]http://www.aisidachina.com/forum/viewthread.php?tid=244[/url]
定义一个按钮连接以下方法:
- (IBAction)selectExistingPicture {
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary])
{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsImageEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:picker animated:YES];
[picker release];
}
else {
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"访问图片库错误"
message:@""
delegate:nil
cancelButtonTitle:@"OK!"
otherButtonTitles:nil];
[alert show];
[alert release];
}
}
再调用以下委托:
#pragma mark UIImagePickerControllerDelegate
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
imageView.image = image; //imageView为自己定义的UIImageView
[picker dismissModalViewControllerAnimated:YES];
}