【发布时间】:2017-07-16 17:27:11
【问题描述】:
我有一个带有背景图片的按钮,我使用SDWebImage 下载。我想通过保持纵横比而不是剪切图像来保持高度不变并改变宽度。只是恒定的高度和动态的宽度。这里有什么问题?
//CODE FROM FUNCTION ---
button.sd_setBackgroundImage(with: url, for: .normal, placeholderImage: UIImage(named: "img"),options: SDWebImageOptions(rawValue: 0), completed: { (image, error, cacheType, imageURL) in
let view = UIView(frame: CGRect(x: 0, y: 0, width: self.resizeImage(image: image!, newHeight: 100), height: 100))
button.frame = view.frame
})
view.addSubview(button)
return view
这是我的辅助函数
func resizeImage(image: UIImage, newHeight: CGFloat) -> CGFloat {
let scale = newHeight / image.size.height
let newWidth = image.size.width * scale
return newWidth
}
【问题讨论】:
-
你看到的输出是什么,添加截图?
-
它现在给了我一个错误,所以我完全走错了路
reason: 'layer <CALayer: 0x60800023cfe0> is a part of cycle in its layer tree
标签: ios swift sdwebimage