SizeThatFits to view with restrictions (automatic layout in layout view)

It is impossible to do impossible

Viewing the layouts that he is viewing, calculating and setting his frames in layoutSubviews.

View B uses the constraints for the layout it is viewing.

View A contains several instances of View B.

View A needs to know the size of its subzones when they are built, so it calls sizeThatFits: on them.

View B height depends on width. In my example, it has multi-line UILabel .

How to implement B sizeThatFits: so that it returns the correct size by taking the size parameter passed to sizeThatFits: and the account restrictions?

What I have tried / thought so far:

systemLayoutSizeFittingSize: - does not work because it does not take into account the exact size passed to it. It cannot be used to indicate the exact width, for example, for a view that grows vertically when it is compressed horizontally. It gives only the most compressed size or the most advanced size.

intrinsicContentSize - this is used to transfer information to the Automatic layout, as I understand it from the documents. We want to receive information from Car Market.

This is how I still reasoned. Please correct me if I make a mistake. And please help me, I would be very grateful if someone could tell me how this is done!

edit: Also, maybe there is a completely different way to do this without even using sizeThatFits: :? The only requirement that I have is that I can continue to use the frame layout in the external view (view A) and the machine in the "internal view" (view B).

edit2: Image added to illustrate the exact case that I have to solve

edit3: Forgot to mention, I need to support iOS 7.0

+5
source share
2 answers

From the image, can UIStackView be the best approach for View A?

https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIStackView_Class_Reference/

then just limit the field offset to the bottom of View A UIStackView to the bottom of the last view B

0
source

I would use Autolayout for the party. You can still specify the exact dimensions and positions, you just do it with restrictions, not frames.

0
source

All Articles