我有一个 UIView,我想在主视图上水平居中,然后在主视图上垂直居中,减去大约 14 像素。
如果我用 IB 设置它,它可以在 Retina 3.5 上运行,但在 Retina 4 上运行时,它当然会偏离大约 40 像素。
我认为最好的解决方案是根据屏幕高度以编程方式建立这些约束?
使用 centerX 和 centerY 常量,并输入常量 14(或 -14 不确定你想要的方式),
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.view attribute:NSLayoutAttributeCenterX relatedBy:0 toItem:view attribute:NSLayoutAttributeCenterX multiplier:1 constant:0]];
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.view attribute:NSLayoutAttributeCenterY relatedBy:0 toItem:view attribute:NSLayoutAttributeCenterY multiplier:1 constant:14]];
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)