Cell Swift中的UITextView [英] UITextView in Cell Swift

查看:118
本文介绍了Cell Swift中的UITextView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经将这些限制弄乱了几个小时,无法弄清楚. 我的文本视图需要具有动态单元格高度.

I have been messing with these constraints for hours and cannot figure this out. I need to have Dynamic cell height with my text view.

您可以看到它与我的时间戳重叠.截至目前,我在时间戳上具有零(无)约束.我已经尝试了所有可能的组合来完成这项工作,但我做不到.

As you can see its overlapping my time stamp. As of right now I have zero(no) constraints on the time stamp. I have tried every combination possible to make this work and I cant get it.

也在使用

   override func viewDidLoad() {
        super.viewDidLoad()



        //TableView Cell word wrap (Dynamic Text)
        self.tableView.dataSource = self
        self.tableView.delegate = self
        self.tableView.estimatedRowHeight = 78
        self.tableView.rowHeight = UITableViewAutomaticDimension

推荐答案

对于Swift 3.1、4.0

这将通过设置约束和UITableViewAutomaticDimensions来实现.

It will be achieved by setting constraints and UITableViewAutomaticDimensions.

第1步:

第2步:

第3步:

第4步:

删除UITextView

第5步:

添加以下代码,

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    return UITableViewAutomaticDimension
}

func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {

    return UITableViewAutomaticDimension
}

注意:

如果您拥有UILabel,则从上述解决方案和label.numberOfLines = 0中将UITextView替换为UILabel.

If you have UILabel then, Replace UITextView to UILabel from above solution and label.numberOfLines = 0.

输出:

这篇关于Cell Swift中的UITextView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆