Custom UIView with dynamic height on storyboard

I want to implement a custom UIView (from code) with dynamic height based on content (similar to UILabel). I can do this by doing intrinsicContentSize - and it seems to work correctly, but ...

When I add my custom view to view the controller on the storyboard, I have an error (no height limit) - even when everything seems to be correctly changed during startup.

When you add UILabel to the storyboard, you do not need to specify the height, there are no errors. How to achieve the same behavior for a custom UIView (I want to use it in a storyboard)?

+7
ios uilabel uiview storyboard
source share
2 answers

If someone needs a solution:

I just found that the Storyboard has the “Intrinsic Size” property - you just need to set it to “Placeholder” and set some values ​​only for Interface Builder ...

enter image description here

+14
source share

I will find out what you create programmatically. try using the following code and improve it in your requirement. Good luck. NSDictionary * views = @ {@ "view": self.view};

  [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[view]|" options:0 metrics:0 views:views]]; [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[view]|" options:0 metrics:0 views:views]]; 
0
source share

All Articles