如何使用设置乘数值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];
Run Code Online (Sandbox Code Playgroud)
使用时没有可用的乘数参数 NSLayoutXAxisAnchor
hConstraint = [view1.centerYAnchor constraintEqualToAnchor:self.view.centerYAnchor constant:0.0f];
Run Code Online (Sandbox Code Playgroud)
只能指定常数值。