1

i am not sure if there is an auto resize container in ios, after some research, there doesn't seem to be any. here is my problem I want to have a container, that contains at most 4 sub elements so I have:

        |A B C D|

i want the container that contains A,B,C, and D to fit exactly (by exactly i mean height and width should be just what it contains)

        so i don't want:
        |A B C D         |

        or 


        |A B C D|
        |       |

now the tricky part is that, sometimes you don't always get A, B, C, D, you could just get arbitrary number of them, in that case, i would also need the container to grow and shrink acoordingly.

        example:
        say we only have A or B
        I expect container to be

        |A B|
        not 
        |A B     |

how i go about to create such container is that I have a UIView to be a container, and i add A, B, C, D subview via addSubview and call [container sizeToFit] this does not work becuase of the thread here Having trouble getting UIView sizeToFit to do anything meaningful in other words, i can't call sizeToFit to generic UIView can someone please help?

edit:

if there is no built in support, can someone provide me a custom code to handle this case?

Community
  • 1
  • 1
user1118019
  • 3,819
  • 8
  • 40
  • 46

1 Answers1

0

You have to implement intrinsicContentSize method with autolayout on.

With this you can specify the content size of your view based on how much elements you have to put on them!

jerrygdm
  • 450
  • 1
  • 7
  • 22