I have a supervisor with three subzones. Two of these views are fixed in size and position within the supervisor, but the third may vary depending on its contents.
I set automatic layout restrictions to set the size and position of each of the sub-items, but what I would like to do is that when changing the contents of the third view, the supervisor must resize so that it can be displayed in full.
I implemented - (NSSize) intrinsicContentSize in this view so that it returns the size that it would like to be, but I cannot decide how to add a constraint that will cause the supervisor to resize.
Any ideas?
UPDATE:
This works for me, adding restrictions to the view as follows:
sizeWidthConstraint = [[NSLayoutConstraint constraintsWithVisualFormat:@"H:[self(==viewWidth)]" options:0 metrics:metrics views:views] lastObject]; sizeHeightConstraint = [[NSLayoutConstraint constraintsWithVisualFormat:@"V:[self(==viewHeight)]" options:0 metrics:metrics views:views] lastObject];
where "viewWidth" and "viewHeight" are the keys in the metrics dictionary with the required values. In udpateConstraints, I will then analyze the contents of my view and do the following:
[sizeHeightConstraint setConstant: size.height]; [sizeWidthConstraint setConstant: size.width];
to set new values, and the following layout will resize the view.
UPDATE in response to the panupan question:
When you create a constraint this way, you can enter what is essentially the name of the variable. In this case, these names are viewWidth and viewHeight. They are known as constraint constants. You also pass a dictionary, called a metric, to a call to [NSLayoutConstratingWithVisualFormat: ...], which gives values ββfor these constants.
So, in this case, I start with the default height and width for my view as the key dictionary values ββof the viewWidth and viewHeight metrics. Later, I use the setConstant: method to change these values. In the above example, size is a CGSize structure that I calculated from the contents of the view (i.e. based on the sizes of its subzones), and I use the width and height values ββto adjust the constants.
This does not achieve what I got after this, because it does not cause the size of my view to automatically change automatically based on the internal dimensions of the subviews, but it gives me the opportunity to repeat the size of it manually.