gpt4 book ai didi

ios - 使用 KingFisher 获取圆形 ImageView (iOS - Swift)

转载 作者:可可西里 更新时间:2023-10-31 23:56:48 25 4
gpt4 key购买 nike

场景:

我有一个@IBOutlet weak var posterImageView: UIImageView!我正在使用 Kingfisher 在我的 tableView 上显示(我必须使用它)。图片来自 API。所以,没关系,图像显示正常,但我想将此图像显示为一个圆圈。我在没有这只翠鸟的情况下做到了,它起作用了,使用:

posterImageView.layer.cornedRadius = posterImageView.frame.size.width/2
posterImageView.clipsToBounds = true

但是对于 kingfisher,我正在这样做:

let imgStg: String = self.movies[indexPath.row].poster!
let imgURL: URL? = URL(string: imgStg)
let imgSrc = ImageResource(downloadURL: imgURL!, cacheKey: imgStg)

cell.posterImageView.kf.setImage(with: imgSrc)

在这个函数中:

    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell

所以,当我在我的 viewDidLoad() 上调用 posterImageView.layer.cornedRadius ... 时,xcode 说我的 TableViewController 上没有这样的 posterImageView。

如何使用这个 kingfisher 调用自定义我的 ImageView ?

最佳答案

如果我理解正确,我认为您应该输入代码以在 cellForRowAtindexPath 方法而不是 viewDidLoad 上获取圆形图像,因此:

  let imgStg: String = self.movies[indexPath.row].poster!
let imgURL: URL? = URL(string: imgStg)
let imgSrc = ImageResource(downloadURL: imgURL!, cacheKey: imgStg)

cell.posterImageView.layer.cornedRadius = posterImageView.frame.size.width/2
cell.posterImageView.clipsToBounds = true
cell.posterImageView.kf.setImage(with: imgSrc)

编辑:记得 KingFisher 支持圆形图像:

let processor = RoundCornerImageProcessor(cornerRadius: 20)
imageView.kf.setImage(with: url, placeholder: nil, options: [.processor(processor)])

希望这两种方式中的一种适合您。

关于ios - 使用 KingFisher 获取圆形 ImageView (iOS - Swift),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43574681/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com