-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
switch (buttonIndex) {
case 0:// 相机
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
}else{
NSLog(@"模拟器无法打开相机");
}
[self presentViewController:picker animated:YES completion:nil];
break;
case 1:// 相册
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:picker animated:YES completion:nil];
break;
default:
break;
}
}
#pragma mark - UIImagePickerControllerDelegate
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
/*添加处理选中图像代码*/
[UIApplication sharedApplication].statusBarHidden = NO;
[picker dismissViewControllerAnimated:YES completion:nil];
UIImage *originImage = [info objectForKey:UIImagePickerControllerOriginalImage]; // 取得相册选取的图片
}
// 相机
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
[picker dismissViewControllerAnimated:YES completion:nil];
}
原文:http://www.cnblogs.com/wlcc/p/3891707.html