delegate:self
cancelButtonTitle:@"取消"
destructiveButtonTitle:@"打開照相機"
otherButtonTitles:@"從手機相冊獲取", nil
];
as.tag=1;
[as showInView:self.view];
//actionSheet協議
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
switch (buttonIndex) {
case 0:{
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
UIImagePickerController *ipc = [[UIImagePickerController alloc]init];
[ipc setSourceType:UIImagePickerControllerSourceTypeCamera];
ipc.delegate = self;
ipc.allowsEditing = YES;
[self presentViewController:ipc animated:YES completion:nil];
}else{
NSLog(@"這設備沒相機");
}
}
break;
case 1:{
UIImagePickerController *ipc = [[UIImagePickerController alloc]init];
[ipc setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
ipc.delegate = self;
ipc.allowsEditing = YES;
[self presentViewController:ipc animated:YES completion:nil];
}
break;
}
}
//選擇完成
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
UIImage*image=[info objectForKey:@"UIImagePickerControllerEditedImage"];
self.sendimg=[NSMutableArray arrayWithObjects:image, nil];
[self dismissViewControllerAnimated:YES completion:^{
}];
}
//取消選擇圖片
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
[self dismissViewControllerAnimated:YES completion:^{
}];
}