I have implemented a custom NSView
which contains many NSTextField
s and other NSView
s. I then embedded that custom view in a scroll vi
To improve on Ken's answer, here is what I did:
• First, I read this wonderful tutorial about how to set up an NSScrollView in Interface Builder (IB) using auto layout.
• Then I did the following:
• Created an NSScrollView
instance in IB;
• Created a new subclass of NSClipView
and added the following code:
class ScCalendarClipView: NSClipView {
open override var isFlipped: Bool {
return true
}
}
• Created the custom document view and embedded it as a child of the NSScrollView instance in IB.
• Added the following constraints in IB in the view I embedded in the NSScrollView instance (let's call it here: DocumentView
)
// Right
First Item: SuperView.Trailing
Relation: Less Than or Equal
Second Item: DocumentView.Trailing
Constant: 0
Priority: 510
Multiplier: 1
First Item: SuperView.Trailing
Relation: Greater Than or Equal
Second Item: DocumentView.Trailing
Constant: 0
Priority: 490
Multiplier: 1
// Left
First Item: DocumentView.Leading
Relation: Equal
Second Item: SuperView.Leading
Constant: 0
Priority: 1000
Multiplier: 1
// Bottom (negative constants increase the size of the document view)
First Item: SuperView.Bottom
Relation: Less Than or Equal
Second Item: DocumentView.Bottom
Constant: -600
Priority: 510
Multiplier: 1
// Bottom (constant should be equal to the bottom constraint above)
First Item: SuperView.Bottom
Relation: Greater Than or Equal
Second Item: DocumentView.Bottom
Constant: -600
Priority: 490
Multiplier: 1
// Top
First Item: DocumentView.Top
Relation: Equal
Second Item: SuperView.Top
Constant: 0
Priority: 1000
Multiplier: 1