iOS读取本地相册

这个在印象笔记里扒出来,做好久了,废话不多说,让我简单粗暴的贴代码吧

//读取本地相册

- (IBAction)didTransformUserPhotos:(id)sender {   
UIActionSheet * sheet=[[UIActionSheet alloc]initWithTitle:@"更改头像" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"拍照"otherButtonTitles:@"选本地图片", nil];
    [sheet showInView:self.view];
}
//actionSheet
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    NSUInteger sourceType;
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
        switch (buttonIndex) {
            case 0:
                //打开相机
sourceType=UIImagePickerControllerSourceTypeCamera;
                break;
            case 1:
            //相册
sourceType=UIImagePickerControllerSourceTypePhotoLibrary;
                break;
            case 2:
                return;
                break;
            default:
                break;
        }
    }else{
        if (buttonIndex==2) {
            return;
            }else{
sourceType=UIImagePickerControllerSourceTypeSavedPhotosAlbum;
        }
    }
    UIImagePickerController * picker=[[UIImagePickerController alloc]init];
    picker.delegate=self;
    picker.allowsEditing=YES;
    picker.sourceType=sourceType;
    [self presentViewController:picker animated:YES completion:nil];
}

猜你喜欢

转载自blog.csdn.net/nefertari_yinc/article/details/50381450