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

照片选择

     // MARK: - 选择照片
     /*----- 选择照片 ------*/
     @IBAction func addImageButtonClick()
     {
         let actionSheet = UIActionSheet(title: "请选择", delegate: self, cancelButtonTitle: "取消", destructiveButtonTitle: nil, otherButtonTitles: "从相册选","拍照")
         actionSheet.showInView(self.view)
     }

     // MARK: - 选取相册
     func fromAlbum()
     {
         //判断设置是否支持图片库
         if UIImagePickerController.isSourceTypeAvailable(.PhotoLibrary)
         {
             //初始化图片控制器
             let picker = UIImagePickerController()

             //设置代理
             picker.delegate = self

             //设置媒体类型
             picker.mediaTypes = [kUTTypeImage,kUTTypeVideo]

             //设置允许编辑
             picker.allowsEditing = true;

             //指定图片控制器类型
             picker.sourceType = UIImagePickerControllerSourceType.PhotoLibrary

             //弹出控制器,显示界面
             self.presentViewController(picker, animated: true, completion: { () -> Void in

             })

         }
         else
         {
             let aler = UIAlertView(title: "读取相册错误!", message: nil, delegate: nil, cancelButtonTitle: "确定")
             aler.show()
         }
     }
 
上一篇:ios开发——实用技术篇Swift篇&拍照


下一篇:ios开发——实用技术篇Swift篇&录音