IOS 选照片

1.效果图
选照片 - wuchaorang.2008 - rang
2.主要代码
(需要实现的协议UIActionSheetDelegate,UINavigationControllerDelegate,UIImagePickerControllerDelegate)
//选择图片

-(IBAction)btnChoosePhoto:(id)sender

{

UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"选 择 图 片"

delegate:self

cancelButtonTitle:@"取消"

                                               destructiveButtonTitle:nil

otherButtonTitles:@"拍照",@"相册",@"图片库",nil];

actionSheet.actionSheetStyle = UIActionSheetStyleDefault;

[actionSheet showInView: self.view];

[actionSheet release];

}

//UIActionSheet协议方法

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

{

    UIImagePickerController *picker=[[UIImagePickerController alloc] init];

    picker.delegate=self;

    picker.allowsEditing=YES;//是否允许编辑

    switch (buttonIndex)

    {

        case 0://照相机

        {

            if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera])

            {

                picker.sourceType=UIImagePickerControllerSourceTypeCamera;

            }

            else

            {

                return;

            }

        }

            break;

        case 1://相册库

        {

if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypePhotoLibrary])

{

picker.sourceType=UIImagePickerControllerSourceTypePhotoLibrary;

}

        }

            break;

        case 2://相册

        {

            if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeSavedPhotosAlbum])

            {

picker.sourceType=UIImagePickerControllerSourceTypeSavedPhotosAlbum;

            }

        }

            break;

           

        default:

        {

            return;

        }

            break;

    }

[self presentModalViewController:picker animated:YES];

[picker release];

}

//UIImagePickerController协议方法

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

{

    //[self.popOverController dismissPopoverAnimated:YES];

[picker dismissModalViewControllerAnimated:YES];

UIImage *image=[info objectForKey:UIImagePickerControllerEditedImage];//取得选择的图片

self.imageView.image=image;

    //[selectButton  setBackgroundImage: image forState: UIControlStateNormal];

}


- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker

{

//[self.popOverController dismissPopoverAnimated:YES];

[picker dismissModalViewControllerAnimated:YES];

}

3.demo下载

http://dl.vmall.com/c0amopjpz1
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值