-(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下载