UITextView in Cell Swift

后端 未结 3 378
滥情空心
滥情空心 2021-01-07 12:56

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 o

3条回答
  •  广开言路
    2021-01-07 13:25

    For Swift 3.1, 4.0

    It will be achieved by setting constraints and UITableViewAutomaticDimensions.

    Step 1:

    Step 2:

    Step 3:

    Step 4:

    Remove Scrolling for UITextView

    Step 5:

    Add Below code,

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

    Note:

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

    Output:

提交回复
热议问题