Dynamic UITableView height

后端 未结 11 1640
無奈伤痛
無奈伤痛 2020-12-29 09:47

I would like to set the UITableView to match the height for all the contents in the table view.

This is my storyboard

The problem with this is the t

11条回答
  •  半阙折子戏
    2020-12-29 10:12

    The answers using the subclassing technique are incomplete. You should also override layoutSubviews() like this.

    public class DynamicSizeTableView: UITableView
    {
        override public func layoutSubviews() {
            super.layoutSubviews()
            if bounds.size != intrinsicContentSize {
                invalidateIntrinsicContentSize()
            }
        }
    
        override public var intrinsicContentSize: CGSize {
            return contentSize
        }
    }
    

提交回复
热议问题