你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發綜合 >> IOS獲取系統相冊中照片的示例代碼

IOS獲取系統相冊中照片的示例代碼

編輯:IOS開發綜合

先來看看效果圖

下面話不多少,我們直接上代碼:

#import "ViewController.h"

@interface ViewController ()<UINavigationControllerDelegate,UIImagePickerControllerDelegate>

@property (weak, nonatomic) IBOutlet UIImageView *IconView;

@end

@implementation ViewController

- (IBAction)chooseImage {

  //彈出系統相冊
  UIImagePickerController *pickVC = [[UIImagePickerController alloc] init];

  //設置照片來源
  pickVC.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
  pickVC.delegate = self;
  [self presentViewController:pickVC animated:YES completion:nil];
}

#pragma mark - UIImagePickerControllerDelegate
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{

  UIImage *photo = info[UIImagePickerControllerOriginalImage];

  UIImageView *imageV = [[UIImageView alloc] init];
  imageV.frame = self.IconView.frame;
  imageV.image = photo;
  imageV.userInteractionEnabled = YES;
  [self.view addSubview:imageV];

  [self dismissViewControllerAnimated:YES completion:nil];
}

@end

總結

以上就是IOS如何獲取系統相冊照片的示例代碼,有需要的朋友們可以直接用,對大家的開發還是很有幫助的,如果大家有疑問可以留言交流。

  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved