美文网首页
IOS 下载现实Image

IOS 下载现实Image

作者: 贼噶人 | 来源:发表于2019-06-24 19:59 被阅读0次
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)
        
    }

相关文章

网友评论

      本文标题:IOS 下载现实Image

      本文链接:https://www.haomeiwen.com/subject/zekaqctx.html