使用KF
加载网络图片后,经常会因为不同的图片处理需要做适配处理
解决方法:
let newUrl = url.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)!
self.bgImage.kf.setImage(with: URL(string: newUrl)) { result in
switch result {
case .success(let value):
let size = value.image.size
let scale = Float(size.height / size.width)
print("--\(size), ---\(scale)")
print("Task done for: \(value.source.url?.absoluteString ?? "")")
case .failure(let error):
print("Job failed: \(error.localizedDescription)")
}
}
网友评论