iT邦幫忙

2018 iT 邦幫忙鐵人賽
DAY 31
0

首先在 UploadImageView 繼承中加入 UIImagePickerController
class UploadImageView: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
    
    var imagePicker: UIImagePickerController!
    
    ...
    
    override func viewDidLoad() {
        super.viewDidLoad()
        image.delegate = self
        imagePicker
    }
    
    
}

接著,把上傳動作指定給 Button

present(imagePickerBtn, animated: true, completion: nil)
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String: Any]) {
//將上傳的圖片轉成 UIImage
    if let image = info[UIImagePickerControllerOriginalImage] as? [UIImage] {
        
        iv_userImage.image = image
    }
    imagePicker.dismiss(animated: true, completion: nil)
}

上一篇
DAY 30: 未完待續
下一篇
請求定位權限及取得目前位置
系列文
Swift 學習目標 -- 30 天送審第一支APP32

尚未有邦友留言

立即登入留言