我在视图控制器中有一个图像视图。我想在用户从库中选择图像时设置此图像。
我试过这个密码:
@IBOutlet var profilePicture: UIImageView!
func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage!, editingInfo: [NSObject : AnyObject]!) {
self.dismissViewControllerAnimated(true, completion:nil)
println("image selected from gallery")
self.profilePicture.image = image
}
它将调试消息打印到控制台,但不会更改映像。我该怎么解决?
最佳答案
你只是忘了把从gallery获得的图像分配给你的UIImageView
。
@IBOutlet var profilePicture: UIImageView!
func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage!, editingInfo: [NSObject : AnyObject]!) {
profilePicture.image = image
self.dismissViewControllerAnimated(true, completion: { () -> Void in
})
println("image selected from gallery")
self.profilePicture.image=image
}
关于ios - 在Swift中从图库中选取图片,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30461868/