iOS 调用相册

来源:互联网 发布:java web访问量统计 编辑:程序博客网 时间:2024/05/02 13:20
[cpp] view plaincopy
  1. 选中某个图片后,显示出来。  
  2. - (void)showPicker  
  3. {  
  4.     UIImagePickerController *picker = [[UIImagePickerController alloc] init];  
  5.     picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;  
  6.     picker.delegate = self;  
  7.     [self presentModalViewController:picker animated:YES];  
  8.     [picker release];  
  9.       
  10. }  
  11.   
  12. // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.  
  13. - (void)viewDidLoad {  
  14.     [super viewDidLoad];  
  15.       
  16.       
  17.     UIButton *button = [UIButton buttonWithType: UIButtonTypeRoundedRect];  
  18.     button.frame = CGRectMake(10.0f, 60.0f, 120.0f, 30.0f);  
  19.     [button setTitle:  @"Picker" forState: UIControlStateNormal];  
  20.     [button addTarget: self action: @selector(showPicker) forControlEvents: UIControlEventTouchUpInside];  
  21.     [self.view addSubview: button];  
  22.       
  23.       
  24.     m_imageView = [[UIImageView alloc] initWithImage: nil];  
  25.     m_imageView.frame = CGRectMake(120.0f, 120.0f, 60.0f, 60.0f);  
  26.     [self.view addSubview: m_imageView];  
  27.       
  28.       
  29. }  
  30.   
  31.   
  32. #pragma mark delegate  
  33. - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)aImage editingInfo:(NSDictionary *)editingInfo  
  34. {  
  35.   
  36.     m_imageView.image = aImage;  
  37.       
  38.     [picker dismissModalViewControllerAnimated:YES];  
  39.       

0 0