Enabling NSScrollView to scroll its contents using Auto Layout in Interface Builder

后端 未结 6 999
时光说笑
时光说笑 2021-01-02 14:17

I have implemented a custom NSView which contains many NSTextFields and other NSViews. I then embedded that custom view in a scroll vi

6条回答
  •  难免孤独
    2021-01-02 14:57

    I'm going to re-post my answer from https://stackoverflow.com/a/49947440/2846508.

    Look at Apple's 2012 developer conference videos about Auto Layout for information about using Auto Layout in code.

    Simply use in Interface Builder or in code the approach I recorded in this video tutorial:

    How to use NSScrollView with Auto Layout

    This is the approach I used in this video:

    1. Window -- set delegate and IBOutlet property

    2. ScrollView -- fixed edges, no border, don't draw background

    3. documentView -- fixed edges 0, then another trailing and bottom, clipView ≥ 0 @499 and clipView ≤ 0 @501 for both trailing and bottom constraints to documentView

    4. label and text field in horizontal stack view, in vertical stack view

    5. vertical stack view fixed edges default, then another bottom, bottom ≤ default @499 and ≥ default @750

    6. horizontal stack view leading and trailing fixed 0

    7. label and text field align Y center to horizontal stack view

    8. text field top and bottom and trailing 2 @750, width ≥ 100, height ≥ 22

    9. subsequent horizontal stack views leading and trailing fixed, align text field leadings

提交回复
热议问题