使用系统相册

2018-01-17  本文已影响8人  友田香菜
image.png

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if indexPath.row == 0{
guard UIImagePickerController.isSourceTypeAvailable(.photoLibrary) else{
print("相册🙅‍♂️")
return
}
let picker = UIImagePickerController()
picker.allowsEditing = false
picker.sourceType = .photoLibrary
picker.delegate = self

        self.present(picker, animated: true, completion: nil)
    }
    
    tableView.deselectRow(at: indexPath, animated: true)
    
}
image.png

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
coverImageView.image = info[UIImagePickerControllerOriginalImage]as?UIImage
coverImageView.contentMode = .scaleAspectFill
coverImageView.clipsToBounds = true

    dismiss(animated: true, completion: nil)
}
image.png image.png
上一篇下一篇

猜你喜欢

热点阅读