gpt4 book ai didi

ios - NSLayoutAnchor - 设置 XAnchor/YAnchor 的乘数

转载 作者:行者123 更新时间:2023-12-01 15:50:33 25 4
gpt4 key购买 nike

如何使用 NSLayoutAnchor 设置乘数值?

例如 ,我们可以使用 NSLayoutConstraint 来做到这一点,乘数值为 1.5:

UIView *view1 = [[UIView alloc] init];
view1.translatesAutoresizingMaskIntoConstraints = false;
view1.backgroundColor = [UIColor redColor];
[self.view addSubview:view1];
NSLayoutConstraint *hConstraint = [NSLayoutConstraint constraintWithItem:view1
attribute:NSLayoutAttributeCenterY
relatedBy:NSLayoutRelationEqual toItem:self.view
attribute:NSLayoutAttributeCenterY
multiplier:1.5 constant:0.0f];

使用 NSLayoutXAxisAnchor 时没有可用的乘数参数
   hConstraint = [view1.centerYAnchor constraintEqualToAnchor:self.view.centerYAnchor constant:0.0f];

只能指定常数值。

最佳答案

有两种变体 NSLayoutAnchor接受乘数但仅在 NSLayoutDimension 上可用的方法 anchor (宽度和高度):

func constraint(equalTo anchor: NSLayoutDimension, multiplier m: CGFloat) -> NSLayoutConstraint
func constraint(equalTo anchor: NSLayoutDimension, multiplier m: CGFloat, constant c: CGFloat) -> NSLayoutConstraint

更多信息请引用 this documentation .

关于ios - NSLayoutAnchor - 设置 XAnchor/YAnchor 的乘数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41691833/

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