我想学迅捷。我有一个简单的演示项目。我有一个变量,它的值是一个指向图像的URL。当我尝试打印此值(变量中编码的URL的值)时,它可以正常工作,但是当我尝试在运行时使用相同变量的值时,它将失败。我应该怎么办?
var picurl : String!
profilePicView.image = UIImage(named: "\(picurl)") // image is not showing with pic url
print("User name --- \(Username)")
print("User picurl --- \(picurl)")// but here value is printed.
谢谢你。
如果您要从URL提取图像,请使用此
if let imageUrl = NSURL(string: \(picurl)) {
if let imageData = NSData(contentsOfURL: imageUrl) {
profilePicView.image = UIImage(data: imageData)
}
}
从本地加载使用此
if let img = UIImage(named: "\(picurl)") {
profilePicView.image = img
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句