ios开发——实用技术篇Swift篇&照片选择

照片选择

 

 1     // MARK: - 选择照片

 2     /*----- 选择照片 ------*/

 3     @IBAction func addImageButtonClick()

 4     {

 5         let actionSheet = UIActionSheet(title: "请选择", delegate: self, cancelButtonTitle: "取消", destructiveButtonTitle: nil, otherButtonTitles: "从相册选","拍照")

 6         actionSheet.showInView(self.view)

 7     }

 8     

 9     // MARK: - 选取相册

10     func fromAlbum()

11     {

12         //判断设置是否支持图片库

13         if UIImagePickerController.isSourceTypeAvailable(.PhotoLibrary)

14         {

15             //初始化图片控制器

16             let picker = UIImagePickerController()

17             

18             //设置代理

19             picker.delegate = self

20             

21             //设置媒体类型

22             picker.mediaTypes = [kUTTypeImage,kUTTypeVideo]

23             

24             //设置允许编辑

25             picker.allowsEditing = true;

26             

27             //指定图片控制器类型

28             picker.sourceType = UIImagePickerControllerSourceType.PhotoLibrary

29             

30             //弹出控制器,显示界面

31             self.presentViewController(picker, animated: true, completion: { () -> Void in

32                 

33             })

34             

35         }

36         else

37         {

38             let aler = UIAlertView(title: "读取相册错误!", message: nil, delegate: nil, cancelButtonTitle: "确定")

39             aler.show()

40         }

41     }

 

 

你可能感兴趣的:(swift)