使用 alamofireimage 在 UIImageview 中显示图像
Show image in UIImageview by using alamofireimage
这似乎是一个愚蠢的问题,但我对 Swift 还是个新手。
我想从 https://httpbin.org/image/png 下载 PNG 图像并使其显示在我的 UIImageView
中,它的名称是 imageView
,但它不起作用。
[Result]: SUCCESS: , {33.333333333333336, 33.333333333333336}
[Timeline]: Timeline: { "Request Start Time": 527346831.982, "Initial Response Time": 527346833.435, "Request Completed Time": 527346833.437, "Serialization Completed Time": 527346833.468, "Latency": 1.453 secs, "Request Duration": 1.455 secs, "Serialization Duration": 0.031 secs, "Total Duration": 1.486 secs }
SUCCESS: , {33.333333333333336, 33.333333333333336}
image downloaded: , {33.333333333333336, 33.333333333333336}
import UIKit
import Alamofire
import AlamofireImage
class ViewController: UIViewController {
@IBOutlet weak var imageView: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
Alamofire.request("https://httpbin.org/image/png").responseImage { response in
debugPrint(response)
debugPrint(response.result)
if let imageView = response.result.value {
print("image downloaded: \(imageView)")
}
}
}
}
您没有将图像设置为您 imageView
的 image
。这是您的代码,已修复:
Alamofire.request("https://httpbin.org/image/png").responseImage { response in
if let image = response.result.value {
self.imageView.image = image
}
}
这似乎是一个愚蠢的问题,但我对 Swift 还是个新手。
我想从 https://httpbin.org/image/png 下载 PNG 图像并使其显示在我的 UIImageView
中,它的名称是 imageView
,但它不起作用。
[Result]: SUCCESS: , {33.333333333333336, 33.333333333333336} [Timeline]: Timeline: { "Request Start Time": 527346831.982, "Initial Response Time": 527346833.435, "Request Completed Time": 527346833.437, "Serialization Completed Time": 527346833.468, "Latency": 1.453 secs, "Request Duration": 1.455 secs, "Serialization Duration": 0.031 secs, "Total Duration": 1.486 secs } SUCCESS: , {33.333333333333336, 33.333333333333336} image downloaded: , {33.333333333333336, 33.333333333333336}
import UIKit
import Alamofire
import AlamofireImage
class ViewController: UIViewController {
@IBOutlet weak var imageView: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
Alamofire.request("https://httpbin.org/image/png").responseImage { response in
debugPrint(response)
debugPrint(response.result)
if let imageView = response.result.value {
print("image downloaded: \(imageView)")
}
}
}
}
您没有将图像设置为您 imageView
的 image
。这是您的代码,已修复:
Alamofire.request("https://httpbin.org/image/png").responseImage { response in
if let image = response.result.value {
self.imageView.image = image
}
}