TableView 内单元格中照片的大小

Posted

技术标签:

【中文标题】TableView 内单元格中照片的大小【英文标题】:Size of a photo in a cell, inside TableView 【发布时间】:2019-11-20 09:46:46 【问题描述】:

我需要把照片的具体尺寸。 在 imageView.image 字段中

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

        let cell = tableView.dequeueReusableCell(withIdentifier: "Quiz Cell", for: indexPath)
        let row = indexPath.row
        let quiz = model.quizzes[row]

        cell.textLabel?.text = quiz.question
        cell.detailTextLabel?.text = quiz.author?.username ?? "Anónimo"
        cell.imageView?.image = UIImage(named: "none")

        return cell
    

【问题讨论】:

上面的代码有什么问题?在 QUIZ 单元格中设置图像的高度和宽度 有什么问题? 您必须在测验单元格中设置它,请提供您的单元格的代码。 代码没有问题。但是我需要设置图像的具体尺寸,我可以在哪里设置这些值? 【参考方案1】:

您需要在单元格本身的Storyboard.xib 中设置特定的imageView 大小。

如果您不使用Storyboard's 或.xib's,也可以通过编程方式进行设置。

【讨论】:

以上是关于TableView 内单元格中照片的大小的主要内容,如果未能解决你的问题,请参考以下文章

两个标签在tableView单元格中垂直对齐自动调整大小

calayer 没有根据 tableview 单元格中的 UIView 大小而改变

tableview不同的单元格在swift中有不同的高度

在集合视图单元格中自行调整图像大小

tableview 单元格我们如何快速调整单元格的大小以及图像和标签

内部另一个表视图的表视图行高