Swift tableViewCell 自适应高度

方法一:

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        switch indexPath.section {
        case 0:
            return 250
        default:
            return UITableView.automaticDimension
        }
    }

方法二:

func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
        //数值为预估高度,随便写影响也不大
        return 250
    }

方法三:

tableView.rowHeight = UITableView.automaticDimension
//或者下面的方法(数值为预估高度,随便写影响也不大)
tableView.estimatedRowHeight = 250

使用方法一的好处是:可以固定某一行高度
而方法二、三的所有行高都由系统自动计算

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容