NSSplitView and autolayout

后端 未结 9 1998
暗喜
暗喜 2021-02-02 10:55

How should I use auto layout constrains inside NSSplitView subview?

My NSSplitView subview has 3 subview: topPane, tableCont

9条回答
  •  礼貌的吻别
    2021-02-02 11:31

    I load all by a nib file and setTranslatesAutoresizingMaskIntoConstraints:NO afterwards.

    So maybe you should first add by [mySplitView addSubview:myView]; your views and disable afterwards the translation of the autosizing mask to constraints and after this you add your contraint to myView.

    EDIT:

    Ok it seems I missunderstand the myView. You have to add the constraint to the subviews and not to the splitview.

    [topPane addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[topPane(34)]" options:0 metrics:nil views:views]];
    
    [bottomPane addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[bottomPane(24)]" options:0 metrics:nil views:views]];
    

    You don't have to add edge constraints (the "|" in "V:|[topPane(34)]") because the subviews in NSSplitView are already autoresizing.

    This lead to this e.g. for the topPane constraint:

    Screenshout

    NOTE: ignore the subview content, they are just placeholders

提交回复
热议问题