U23*_*23r 2 uiimageview ios swift kingfisher
我有一个@IBOutlet弱变量posterImageView:UIImageView!我正在使用Kingfisher在我的tableView上显示(我必须使用它).该图像来自API.所以,没关系,图像显示正常,但我想将此图像显示为圆形.我没有这个翠鸟,它工作,使用:
posterImageView.layer.cornedRadius = posterImageView.frame.size.width/2
posterImageView.clipsToBounds = true
Run Code Online (Sandbox Code Playgroud)
但是对于翠鸟,我这样做:
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)
Run Code Online (Sandbox Code Playgroud)
在这个功能里面:
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
Run Code Online (Sandbox Code Playgroud)
所以,当我在viewDidLoad()上调用posterImageView.layer.cornedRadius ...时,xcode会说我的TableViewController上没有这样的posterImageView.
如何使用此翠鸟电话自定义图像视图?
JP *_*ino 11
如果我理解正确,我认为你应该输入代码来获取你的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)
Run Code Online (Sandbox Code Playgroud)
编辑:记得KingFisher支持圆形图像:
let processor = RoundCornerImageProcessor(cornerRadius: 20)
imageView.kf.setImage(with: url, placeholder: nil, options: [.processor(processor)])
Run Code Online (Sandbox Code Playgroud)
希望这两种方式中的一种适合你.