我可以为 Autolayout 中的默认 Aqua 空间使用什么常量? [英] What constant can I use for the default Aqua space in Autolayout?

查看:19
本文介绍了我可以为 Autolayout 中的默认 Aqua 空间使用什么常量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据Cocoa Auto Layout Guide,我可以用视觉约束格式语言中的破折号来表示标准Aqua空间:"

According to the Cocoa Auto Layout Guide, I can use a dash in the visual constraint format language to "denote the standard Aqua space:"

[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"[a]-[b]"
                                                             options:0
                                                             metrics:nil
                                                               views:viewDict]];

但是,如果我正在构建一个约束没有,我似乎找不到一个 NSLayout... 常量或方法可以让我做同样的事情使用视觉格式语言:

However, I can't seem to find an NSLayout... constant or method that allows me to do the same thing if I'm building a constraint without using the visual format language:

[self addConstraint:[NSLayoutConstraint constraintWithItem:a
                                                 attribute:NSLayoutAttributeTrailing
                                                 relatedBy:NSLayoutRelationEqual
                                                    toItem:b
                                                 attribute:NSLayoutAttributeLeading
                                                multiplier:1.0f
                                                  constant:<# ??? #>]];

在这种情况下,我可以使用一个常量(或其他值或方法)来定义 Aqua 空间吗?

Is there a constant (or another value or method) that I can use to define the Aqua space in such a situation?

推荐答案

我发现标准 Aqua 空间"在兄弟视图之间为 8.0,在视图与其父视图之间为 20.0.

I've found the "standard Aqua space" to be 8.0 between sibling views, and 20.0 between a view and its superview.

NSView* view = [NSView new] ;
NSLayoutConstraint* constraintWithStandardConstantBetweenSiblings = [NSLayoutConstraint constraintsWithVisualFormat:@"[view]-[view]"  options:0  metrics:nil  views:NSDictionaryOfVariableBindings(view) ] [0] ;
CGFloat standardConstantBetweenSiblings = constraintWithStandardConstantBetweenSiblings.constant ;    // 8.0

NSView* superview = [NSView new] ;
[superview addSubview:view] ;
NSLayoutConstraint* constraintWithStandardConstantBetweenSuperview = [NSLayoutConstraint constraintsWithVisualFormat:@"[view]-|"  options:0  metrics:nil  views:NSDictionaryOfVariableBindings(view) ] [0] ;
CGFloat standardConstantBetweenSuperview = constraintWithStandardConstantBetweenSuperview.constant ;    // 20.0

这篇关于我可以为 Autolayout 中的默认 Aqua 空间使用什么常量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆