1.弹出相册和相框的提示框
UIActionSheet* actionSheet = [[UIActionSheetalloc]
initWithTitle:@"请选择照片来源"
delegate:self
cancelButtonTitle:@"取消"
destructiveButtonTitle:nil
otherButtonTitles:@"照相机",@"本地相簿",nil];
[actionSheetshowInView:self.view];
2.
NSLog(@"buttonIndex = [%ld]",(long)buttonIndex);
switch(buttonIndex) {
case0://照相机
{
UIImagePickerController*imagePicker = [[UIImagePickerControlleralloc]init];
imagePicker.delegate=self;
imagePicker.allowsEditing=YES;
imagePicker.sourceType=UIImagePickerControllerSourceTypeCamera;
[selfpresentViewController:imagePickeranimated:YEScompletion:nil];
}
break;
case1://本地相簿
{
UIImagePickerController*imagePicker = [[UIImagePickerControlleralloc]init];
imagePicker.delegate=self;
imagePicker.allowsEditing=YES;
imagePicker.sourceType=UIImagePickerControllerSourceTypePhotoLibrary;
[selfpresentViewController:imagePickeranimated:YEScompletion:nil];
}
break;
default:
break;
}
3.实现相机相册的代理方法
- (void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary*)info{
UIImage*img = [infoobjectForKey:UIImagePickerControllerEditedImage];
[pickerdismissViewControllerAnimated:YEScompletion:nil];
}
取消
- (void)imagePickerControllerDidCancel:(UIImagePickerController*)picker{
}