最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

[已解决]Swift中UITableViewCell中根据要显示的文字自动计算cell的高度

Swift crifan 3985浏览 0评论
折腾:
期间,还是先去解决:
现在是手动设置的固定的cell的高度。

如何根据要显示的文字,单行的,多行的等待,

去动态的计算cell的高度。
[折腾过程]
1.搜:
swift UITableViewCell calculate cell height for multiple line text
swift UITableView calculate cell height for multiple line text
参考:
tableView的rowHeight设置为UITableViewAutomaticDimension
estimatedRowHeight设置为一个正常的值
去掉heightForRowAtIndexPath
示例代码:
    override func viewDidLoad() {
super.viewDidLoad()

。。。
chatTableView?.rowHeight = UITableViewAutomaticDimension
chatTableView?.estimatedRowHeight = 40

self.view.addSubview(chatTableView!)

    }
//    func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
//        return calculatedChatHeight
//    }
//
供参考。
多行效果+自动计算高度的效果:
uitableviewcell multiple line auto calc height

转载请注明:在路上 » [已解决]Swift中UITableViewCell中根据要显示的文字自动计算cell的高度

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
85 queries in 0.171 seconds, using 22.13MB memory