首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >对于Autolayout中的默认Aqua空间,我可以使用什么常量?

对于Autolayout中的默认Aqua空间,我可以使用什么常量?
EN

Stack Overflow用户
提问于 2012-12-27 14:01:55
回答 3查看 5.1K关注 0票数 23

根据可可自动布局指南,我可以使用视觉约束格式语言中的破折号来“表示标准的Aqua空间:”

代码语言:javascript
运行
复制
[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"[a]-[b]"
                                                             options:0
                                                             metrics:nil
                                                               views:viewDict]];

但是,如果不使用可视化格式语言构建约束,我似乎找不到一个NSLayout...常量或方法允许我做同样的事情:

代码语言:javascript
运行
复制
[self addConstraint:[NSLayoutConstraint constraintWithItem:a
                                                 attribute:NSLayoutAttributeTrailing
                                                 relatedBy:NSLayoutRelationEqual
                                                    toItem:b
                                                 attribute:NSLayoutAttributeLeading
                                                multiplier:1.0f
                                                  constant:<# ??? #>]];

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

EN

Stack Overflow用户

发布于 2013-09-28 01:55:01

对于iOS用户:

代码语言:javascript
运行
复制
#import "NSLayoutConstraint+StandardOffsets.h"

@implementation NSLayoutConstraint (StandardOffsets)

+ (CGFloat)standardConstantBetweenSiblings
{
    static CGFloat value;

    if(!isnormal(value)) {
        UIView *view = [UIView new] ;
        NSLayoutConstraint* constraintWithStandardConstantBetweenSiblings = [NSLayoutConstraint constraintsWithVisualFormat:@"[view]-[view]"  options:0  metrics:nil  views:NSDictionaryOfVariableBindings(view) ] [0] ;
        value = constraintWithStandardConstantBetweenSiblings.constant ;    // 8.0
    }
    return value;
}

+ (CGFloat)standardConstantBetweenSuperview
{
    static CGFloat value;

    if(!isnormal(value)) {
        UIView *view = [UIView new] ;
        UIView *superview = [UIView new] ;
        [superview addSubview:view] ;
        NSLayoutConstraint* constraintWithStandardConstantBetweenSuperview = [NSLayoutConstraint constraintsWithVisualFormat:@"[view]-|"  options:0  metrics:nil  views:NSDictionaryOfVariableBindings(view) ] [0] ;
        value = constraintWithStandardConstantBetweenSuperview.constant ;    // 20.0
    }
    return value;
}

@end

PS:我输入了一个在头文件中不提供常量的bugreport!

票数 10
EN
查看全部 3 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14055900

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档