标签:
第一步点击获取头像按钮 下面为按钮执行方法
判断设备是否具有照像机功能有的话执行前者方法没有执行后者方法
UIActionSheet *actionSheet;
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){
actionSheet = [[UIActionSheet alloc]initWithTitle:@"选择图像" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"拍照", @"从相册选
择", nil,nil];
}else{
actionSheet = [[UIActionSheet alloc] initWithTitle:@"选择图像" delegate:self cancelButtonTitle:@"取消"destructiveButtonTitle:nil otherButtonTitles:@"从相册选择", nil];
}
actionSheet.tag = 1000;
[actionSheet showInView:self.view];
第二步 执行调用相机或者相册方法 当然了还要引用代理UINavigationControllerDelegate, UIImagePickerControllerDelegate
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
if (actionSheet.tag == 1000) {
NSUInteger sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
// 判断是否支持相机
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
switch (buttonIndex) {
case 0:
sourceType = UIImagePickerControllerSourceTypeCamera;
break;
case 1:
//来源:相册
break;
case 2:
return;
}
}
else {
if (buttonIndex == 2) {
return;
} else {
sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
}
}
// 跳转到相机或相册页面
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.delegate = self;
imagePickerController.allowsEditing = YES;
imagePickerController.sourceType = sourceType;
[self presentViewController:imagePickerController animated:YES completion:^{
}];
}
}
第三步就是确定头头像了
#pragma mark - 头像
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[picker dismissViewControllerAnimated:YES completion:nil];
UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];
NSLog(@"%@",image);
_faceImage = image;
[_tableView reloadData];
}
第四步就是你要把选中的图片显示在上面地方就显示在上面地方 这图片就是 _faceImage直接调用就好
标签:
原文地址:http://www.cnblogs.com/daijiahong/p/5058781.html