I want to create collection view cells the width of which changes according to the label in them. The labels of the cells get their text value from an array declared by me. Is there a way to create auto resizable collection view cells which change their length accordingly without using custom classes or pod files?
Asked
Active
Viewed 107 times
1
-
Answered this question here: https://stackoverflow.com/a/63670539/ – williamfinn Sep 04 '21 at 12:41
-
Thank you sir, it worked for me too, however, my collection view is like a matrix with rows and sections, any suggestions for this scenario? – NoName555 Sep 04 '21 at 14:34
-
So you would like a grid that sizes each cell both vertically and horizontally ? – williamfinn Sep 04 '21 at 16:05
-
@williamfinn Yes, pricesly – NoName555 Sep 05 '21 at 15:57
-
you could easily achieve that with collection view, I am not really sure why are you trying with table view. Or is that in the existing project and you gotta make changes there? – Joke coder Sep 08 '21 at 05:37
1 Answers
0
Try experimenting with UIStackView. I'm pretty sure the elements can be auto justified. You'll likely be able create the layout you want with vertical and horizontal stack views.
If you select multiple views in the interface builder that are arranged horizontally or vertically you can embed them in a stack view.
if you multi select the views you want and press that button in the lower right corner of interface builder you should have an option to embed the views in a UIStack View

user3589502
- 51
- 1
- 1
- 3