作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我几乎完成了我的项目,只是发现字体和中间的空格在 iPhone 6Plus 中看起来很奇怪。
我已经创建了所有用于拖放 XIB 文件的约束。我的同事在全局函数上添加了这些代码,以便我可以应用乘数:
- (float)constraintScale {
if (IS_STANDARD_IPHONE_6_PLUS) {
return 1.29;
}
return 1.0;}
- (float)textScale {
if (IS_STANDARD_IPHONE_6_PLUS)
{
return 1.16;
}
return 1.0; }
我现在的问题是必须将每个(超过 100 个)约束拖到我的代码中,并使用这些乘数和比例应用每个约束。有没有更方便的方法向我的 XIB 文件添加乘数?我考虑过子类化,但这可能需要相同的时间?
最佳答案
self.view.constraints
将为您提供 View 的所有约束。
for(NSLayoutConstraint *c in self.view.constraints)
{
c.multiplier = [self constraintScale];
}
可能会起作用。希望对您有所帮助。
编辑:抱歉只读问题。解决这个问题的另一种方法可能是;
NSMutableArray *constraintsNew = [NSMutableArray new];
for (NSLayoutConstraint *c in self.view.constraints)
{
NSLayoutConstraint *newC = [NSLayoutConstraint constraintWithItem:c.firstItem
attribute:c.firstAttribute
relatedBy:c.relation
toItem:c.secondItem
attribute:c.secondAttribute
multiplier:[self constraintScale]
constant:c.constant];
[constraintsNew addObject:newC];
}
[self.view removeConstraints:self.view.constraints];
[self.view addConstraints:constraintsNew];
关于ios - 如何将乘数应用于在 nib 文件上创建的所有约束?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31586706/
我是一名优秀的程序员,十分优秀!