[英]Custom UIView with dynamic height on Storyboard
I want to implement custom UIView (from code) with dynamic height, based on content (similar to UILabel). 我想基于内容(类似于UILabel)实现具有动态高度的自定义UIView(来自代码)。 I can do this by implementing
intrinsicContentSize
- and it seems to work correctly, but... 我可以通过实现
intrinsicContentSize
来实现这一点 - 它似乎正常工作,但......
When I am adding my custom view to view controller on storyboard, I've got error (missing height constraint) - even when during launch everything seems to resize correctly. 当我将自定义视图添加到故事板上的视图控制器时,我有错误(缺少高度约束) - 即使在启动期间,所有内容似乎都正确调整大小。
When you add UILabel to storyboard you don't have to specify height, there are no errors. 将UILabel添加到情节提要板时,您不必指定高度,也没有错误。 How to achieve the same behavior for custom UIView (I want to use it in storyboard)?
如何为自定义UIView实现相同的行为(我想在故事板中使用它)?
i come to know that you are creating by programmatically. 我知道你是通过编程方式创建的。 try to use the following code and improve it in your requirement .
尝试使用以下代码并根据您的要求进行改进。 Best of luck.
祝你好运。 NSDictionary* views = @{@"view" : self.view};
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]];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.