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];
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章