使用带有 UIButton 的 URL 图像

JSh*_*rpp 1 uibutton uiimage ios afnetworking swift

我试图在 swift 4 中将 URL 图像设置为 UIButton。我正在使用 AFNetworking 从 URL 加载我的图像。我正在了解将图像设置为按钮的最佳途径是什么。

使用.setImage()setImageWith()不适用于 urls 和 uibuttons。

这是正在使用的 URL:

let imageUrl = URL(string: baseUrl + profile)

Sh_*_*han 5

您可以使用SDWebImage它有一个类别/引伸为UIButton

btn.sd_setImage(with:URL(string: "Your_url"), forState:.normal)
Run Code Online (Sandbox Code Playgroud)