What constant can I use for the default Aqua space in Autolayout?

后端 未结 3 712
庸人自扰
庸人自扰 2020-12-13 20:12

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 addConstrain         


        
3条回答
  •  自闭症患者
    2020-12-13 20:36

    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
    

提交回复
热议问题