小编use*_*205的帖子

NSLayoutAnchor - 设置 XAnchor/YAnchor 的乘数

如何使用设置乘数值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)

只能指定常数值。

iphone uikit ios

5
推荐指数
1
解决办法
1622
查看次数

标签 统计

ios ×1

iphone ×1

uikit ×1