Is it possible to have differing heights in a UITableView Cell when I use several different ways of displaying the cell?

后端 未结 11 1311
一整个雨季
一整个雨季 2020-12-21 19:25

I\'ve spent several days trying to figure this out, but there doesn\'t seem to be a solution. I have a very basic UITableView cell with two labels in it. One of them will be

11条回答
  •  无人及你
    2020-12-21 19:51

    I suggest you don't use stack view for this . Just take custom cell with Label according to your requirement and cell will resize automatically according to Label text size.

    Check , here i have attached demo.

    UITableview cell Autoresize According to textsize

    Output :-

    In viewdidload

    super.viewDidLoad()
            self.tblView.estimatedRowHeight = 100;
            self.tblView.rowHeight = UITableViewAutomaticDimension;
            self.tblView.setNeedsLayout()
            self.tblView.layoutIfNeeded()
    

    Dont forget to set Numberoflines=0 of UILabel property.

    Edit :- If you need step by step guide regarding how to set constrain to UILabel ,

    check this link ,

    Adjust UILabel height depending on the text

    Edit :- Here i have take 2 label in cell according to your above image. Just set constrain like this .

    Label 1 :- Top , Leading , (Height and width According to your requirement)

    Label 2 :- Top , Bottom , Leading from Label 1, Trailing from Superview

提交回复
热议问题