override func viewDidLoad() {
super.viewDidLoad()
imageView = UIImageView.init(frame: CGRect.init(x: 0, y: (UIScreen.main.bounds.height - UIScreen.main.bounds.width * 9 / 16)/2 , width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.width * 9 / 16))
imageView!.contentMode = .scaleAspectFill
view.addSubview(imageView!)
URLSession.shared.dataTask(with: URL.init(string: "http://images.xuejuzi.cn/1612/1_161207205812_1.jpg")!, completionHandler: {
data,response,error in
if let response = response {
print("\(response)")
}
if let data = data {
let image = UIImage.init(data: data)
DispatchQueue.main.async {
print("\(Date.init().timeIntervalSince1970)")
self.imageView!.image = image
print("\(Date.init().timeIntervalSince1970)")
}
}
}).resume()
// imageView?.image = downsample(imageAt: URL.init(string: "http://images.xuejuzi.cn/1612/1_161207205812_1.jpg")!, to: CGSize.init(width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.width * 9 / 16), scale: 0.5)
}
网友评论