0
如何使自定义的可加载脚本的UIView/Widget适合在故事板中为其提供的容器?也就是说,你如何让它占据指定的空间,不多也不少?使用自动布局时,自定义UIView不适合其故事板容器
如何使自定义的可加载脚本的UIView/Widget适合在故事板中为其提供的容器?也就是说,你如何让它占据指定的空间,不多也不少?使用自动布局时,自定义UIView不适合其故事板容器
什么最有可能是在这种情况下被遗忘的是添加以下代码加载笔尖并将其添加到自定义视图的/控件的子视图的背景:
UIView* rootView = [[[NSBundle mainBundle]
loadNibNamed:className owner:self options:nil] firstObject];
rootView.translatesAutoresizingMaskIntoConstraints = NO;
[self addConstraint:
[NSLayoutConstraint
constraintWithItem:rootView attribute:NSLayoutAttributeTop
relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeTop
multiplier:1.0f constant:0.0f]];
// And so on for all attributes (Bottom, Left, Right) that you want to
// constrain the loaded nib with.
(其中自是自定义的UIView/Widget实例。)