gpt4 book ai didi

ios - 使用图像选择器的三个图像

转载 作者:行者123 更新时间:2023-12-01 16:33:11 25 4
gpt4 key购买 nike

我正在构建一个允许用户向三张UIImageViews添加三张图片的应用
我添加了三个按钮,例如,当用户单击一个按钮时,他应该能够将图像添加到UIImageView 1
但是图像没有出现在UIImageView上,我没有找到任何解决方案

代码示例:

 @IBAction func imageOneBtn(sender: AnyObject) {
picker.sourceType = UIImagePickerControllerSourceType.PhotoLibrary
picker.delegate = self
picker.allowsEditing = false
self.presentViewController(picker, animated: true, completion: nil)

func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject : AnyObject]){
let selectedImage = info[UIImagePickerControllerOriginalImage] as! UIImage
imageViewOne.image = selectedImage
imageViewOne.contentMode = UIViewContentMode.ScaleAspectFit
picker.dismissViewControllerAnimated(true, completion: nil)
}
}

先感谢您

最佳答案

该代码似乎是正确的。

let selectedImage = info[UIImagePickerControllerOriginalImage] as! UIImage

尝试删除感叹号(!)。

尝试使用 imageViewOne.contentMode = .ScaleAspectFit
也尝试使用 var而不是 let selectedImage
一般来说,尝试此代码
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject : AnyObject]) {
var selectedImage = info[UIImagePickerControllerOriginalImage] as UIImage
imageViewOne.contentMode = .ScaleAspectFit
imageViewOne.image = selectedImage
dismissViewControllerAnimated(true, completion: nil)
}

关于ios - 使用图像选择器的三个图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30620181/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com