【问题标题】:How to add Kingfisher for a UIImage without a URL in Swift?如何在 Swift 中为没有 URL 的 UIImage 添加 Kingfisher?
【发布时间】:2021-08-24 09:52:12
【问题描述】:

我已将 Kingfisher 添加到 tableview 单元格中的 UI 图像,但它无法正常工作。下面是我之前尝试过的代码示例,

directoryPresenter!.getProfileImage(id:(directoryPresenter!.getEmployeeItem(position: indexPath.row).employeeID)) { image in
      cell.profileImage.kf.base.image = image
   // cell.profileImage.image = image
}

我们可以在不传递 URL 的情况下将 Kingfisher 添加到 UI 图像吗?我发现的大多数问题都与 URL 有关。请帮我解决问题

【问题讨论】:

  • 你显示的是在线图片还是本地保存的图片?
  • “我已将 Kingfisher 添加到 tableview 单元格中的 UI 图像”是什么意思?如何将 Kingfisher 添加到 UIImage 对象?

标签: ios swift swift5 kingfisher


【解决方案1】:

如果你使用的是本地保存的图片,则不需要使用 Kingfisher,只需这样做:

cell.profileImage.image = image

如果您想使用 url 显示图像,请这样做:

cell.profileImage.kf.setImage(with: {imageURL})

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-06-02
    • 1970-01-01
    • 2018-07-03
    • 1970-01-01
    • 1970-01-01
    • 2015-10-26
    • 2023-04-06
    • 1970-01-01
    相关资源
    最近更新 更多