点击图片 更换头像

点击图片 更换头像

<UIActionSheetDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate>

 UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"选择图像" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"拍照" otherButtonTitles:@"从相册选择", nil];

     [sheet showInView:self.view];

    [sheet release];

 }

 #pragma mark -- imagePickerControllerDelegate

 //获取图片后触发

 - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

    self.imageView.image = [info objectForKey:UIImagePickerControllerOriginalImage];

    [picker dismissViewControllerAnimated:YES completion:nil]; 

}

#pragma mark - handle Photo

//action sheet 响应事件

 - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {

    //创建对象

    UIImagePickerController *imagePicker = [[[UIImagePickerController alloc] init] autorelease];

 

    //相片来源:1.photoAlum 2.camera 3.photoLibrary

 

    //指定相片来源

 

    switch (buttonIndex) {

 

        case 0: //拍照

 

            //判断是否支持相机

 

            if ([UIImagePickerController isSourceTypeAvailable:(UIImagePickerControllerSourceTypeCamera)]) {

 

                imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;

 

            } else {

 

                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"不支持相机拍照,请重新选择" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:nil, nil];

 

                [alert show];

 

                [alert release];

 

                return;

 

            }

 

            break;

 

        case 1:

 

            imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; //从相册选择

 

            break;

 

        case 2:

 

            return; //取消

 

        default:

 

            break;

 

    }

 

    //跳转模式

 

    imagePicker.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;

 

    //指定代理

 

    imagePicker.delegate = self;

 

    //弹出视图

 

    [self presentViewController:imagePicker animated:YES completion:nil];

 

}

转载于:https://www.cnblogs.com/tapple/p/4871613.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值