我正在尝试使用Autolayout构建应用程序。使用情节提要和编程方式对其进行了尝试,但没有运气。视图的行为不符合预期。
这是输出屏幕。(针对iOS7)
问题:我希望绿色按钮位于红色按钮的正上方,垂直间隙为10px。但是红色按钮在3.5英寸显示屏上重叠,在4英寸显示屏上正确。
下面是我尝试的代码。
[self.btnGreen setTranslatesAutoresizingMaskIntoConstraints:NO];
[self.viewContainer addConstraint:[NSLayoutConstraint constraintWithItem:self.btnGreen attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:self.viewContainer attribute:NSLayoutAttributeHeight multiplier:1.0 constant:100.0]];
[self.viewContainer addConstraint:[NSLayoutConstraint constraintWithItem:self.btnGreen attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:self.viewContainer attribute:NSLayoutAttributeWidth multiplier:1.0 constant:100.0]];
我引用了以下链接:1)苹果指南2)http://matthewmorey.com/ 3)也是这个
但是没有得到想要的输出。
任何帮助将不胜感激。
尝试这些约束,如图所示:
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句