Search code examples
swiftnstextfieldnsscrollview

NSScrollView with several TextFields


I'm trying to create simple application (for testing purpose) with NSScrollView and 2 multi-line labels inside it (title and document). I can't use integrated TextView because I need 1 general scroller to scroll all content, not just for one selected TextView.

So generally I need fixed one-line title and document text with shared scroller.

I have no mind how to make this.

I've attached my sample project (only Storyboards) with scoller, you can take a look here: scroller.zip


Solution

  • I'm not sure if this is possible in the designer, but it is possible to set correct constraints in the runtime. Follow the steps:

    1. In the storyboard select your text field
    2. Set bottom margin constraint (28 in your example)
    3. Set height constraint (242 in your example)
    4. Connect the height constraint to an outlet in the viewcontroller (for example @IBOutlet weak var labelHeightConstraint: NSLayoutConstraint!)
    5. In the viewcontroller's viewDidLoad method set constraints height to expected height (for example
      labelHeightConstraint.constant = 1000)
    6. Run :)

    Hope it helps!