Align Toolbar Item to split view content unsing Auto Layout Constraints

后端 未结 2 443
既然无缘
既然无缘 2020-12-21 05:15

I would like to align a button in the toolbar of an os x app to the position of a split view in the window, similar to the delete button in Apple Mail. How can this be done

2条回答
  •  清酒与你
    2020-12-21 06:06

    I know it's a bit old, but I had the same issue and found an answer:

    You have to use topLayoutGuide property.

    Ex in swift

    view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormats(
            ["H:|[toolbarShadow]|", "V:[topLayoutGuide][toolbarShadow(100)]"], 
    views: viewDictionnary))
    

    Of course topLayoutGuide must be in your view dictionary

    You can access it through self.topLayoutGuide

提交回复
热议问题