Aditi Tiwari Aditi Tiwari - 1 month ago 10
iOS Question

How to set the on UITableView cell width different from the selection of segment button in objc on one view using only one cell

I Have a view in which a segment controller ,I have used with two selection.
So here I just want to increase the width of cell containing label with address on first selection rather decrease the width by second selection,and here I used one cell and also using autoresizing in it.
Views are attached in it.Please have a lookView on selection of second segment index 2

Views on selection of second segment index 1


I understand it as that you want the address to fill the space taken up by the price when there is no price to show, there I suggest to:

Use Constraints

You can set a constraint for space between the address label and the price label. Then a constraint between the price label and the trailing margin. On scenarios where you do not need the price, set it's width to 0 and the address will stretch to fill up the space.

And since you are reusing the cell, remember to reset the width in prepareForReuse of the cell.