ios - 应用程序上的图像太小,而且有很多空白单元格,我怎样才能让我的图像变大,以便它可以容纳我手机屏幕的一半?
问题描述
显示时图像很小,如何将其缩小到手机大小的一半?
import UIKit
import Kingfisher
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet var tableview: UITableView!
var arrayOfImages = ["https://firebasestorage.googleapis.com/v0/b/starlaxcy.appspot.com/o/myimage.png?alt=media&token=adcfa5ce-5bc3-4a65-bdcd-fb190f4c38d2"]
override func viewDidLoad() {
self.tableview.register(ImageCell.self, forCellReuseIdentifier: "ImageCell")
super.viewDidLoad()
}
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return arrayOfImages.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "ImageCell") as! ImageCell
let resource = ImageResource(downloadURL: URL(string: arrayOfImages[indexPath.row])!, cacheKey: arrayOfImages[indexPath.row])
cell.imageView?.kf.setImage(with: resource)
return cell
}
}
解决方案
如果您有自定义单元格ImageCell
let cell = tableView.dequeueReusableCell(withIdentifier: "ImageCell") as! ImageCell
不要imageView
设置超类的内置属性UITableViewCell
cell.imageView?.kf.setImage(with: resource)
而是创建一个 imageView ,在该类的 init 方法中添加适当的约束并将其与 kingfisher 一起使用
推荐阅读
- laravel - 从包中下拉以显示国家和州
- php - Laravel 从 SQL Server 下载 varbinary 文件
- java - StringBuffer 与普通打印
- python - 如何在 2 个不同的数据框中映射列值
- firebase - 如何使用 Flutter 和 Firebase 验证用户电子邮件
- c++ - 如何在 Eclipse 中配置 RTEMS?
- django - Django 1.11 - 如何使用仅支持 NTLM 身份验证的邮件服务器发送邮件
- python - 在python中if == ok时创建列表
- rest-assured - 从 Rest Assured 响应中提取嵌套值
- php - PHP 使用带有 google QR 码 api 的变量