【问题标题】:How to set automatic height in heighForRowAt indexPath?如何在 heighForRowAt indexPath 中设置自动高度?
【发布时间】:2021-02-19 15:35:54
【问题描述】:

我尝试每次数数以使 UIImage 完美大小,所以我正在制作漫画应用程序,我可以在没有设置数字的情况下上传以使其完美。

我尝试从 Storyboard 使用的 ComicsCell (UITableViewCell) 中导入 IMG。 在这里,我尝试研究了将近 2 周,但没有找到自动 UIImage Height 的技巧。

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return Int(comicsCells.IMG.bounds.height)
        // error: Cannot find 'comicsCells' in scope
    }

如果您发现任何代码可以让我自己导入具有自动高度的图像,请告诉我。

谢谢!

【问题讨论】:

    标签: swift uitableview uiimage height


    【解决方案1】:

    你可以试试这样的自动维度:

    func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
        return UITableView.automaticDimension
    }
    

    PS:此功能需要顶部和底部约束。

    查看this 的帖子。

    【讨论】:

    • 不错的一个!但我不喜欢给我做很多工作来做上下或做这样的数字。我已经看到一些漫画应用程序只是导入到应用程序中,它在上传时会自动调整高度,不管这样的高度数。我很难这样想。
    猜你喜欢
    • 1970-01-01
    • 2021-11-02
    • 2012-10-07
    • 1970-01-01
    • 2019-03-11
    • 1970-01-01
    • 2013-02-21
    • 2016-04-25
    • 2015-09-24
    相关资源
    最近更新 更多