我有一個應用程序,我正在開發的功能允許用戶拍照或從照片庫中選取圖像。該代碼有效,但圖像總是顯示大於UIImageView
框。該框被設置爲在故事板中「縮放縱橫比」,但相機圖像拒絕符合。相機圖像調整大小
下面的代碼:
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
if let chosenImage = info[UIImagePickerControllerOriginalImage] as? UIImage{
imageField.image = chosenImage
} else{
//error message goes here
}
self.dismiss(animated: true, completion: nil)
}
我怎麼chosenImage
,以符合框或方面配合?
嘗試用'ScaleAspectFill'和'clipsToBounds =真' –