您的位置:首页 > 移动开发 > IOS开发

iOS读取本地相册

2015-12-22 17:53 369 查看
这个在印象笔记里扒出来,做好久了,废话不多说,让我简单粗暴的贴代码吧

//读取本地相册

- (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];
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ios