gpt4 book ai didi

ios - 如何将乘数应用于在 nib 文件上创建的所有约束?

转载 作者:行者123 更新时间:2023-11-29 12:17:47 24 4
gpt4 key购买 nike

我几乎完成了我的项目,只是发现字体和中间的空格在 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com