How to make scrollable vertical NSStackView

Issue #173

You might need to flip NSClipView

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import AppKit
import Anchors
import Omnia

final class ScrollableStackView: NSView {
final class FlippedClipView: NSClipView {
override var isFlipped: Bool {
return true
}
}

override init(frame frameRect: NSRect) {
super.init(frame: frameRect)
setup()
}

required init?(coder decoder: NSCoder) {
fatalError()
}

let stackView: NSStackView = withObject(NSStackView()) {
$0.orientation = .vertical
}

private let scrollView: NSScrollView = NSScrollView()

private func setup() {
addSubview(scrollView)
scrollView.hasVerticalScroller = true
scrollView.drawsBackground = false

activate(
scrollView.anchor.edges
)

let clipView = FlippedClipView()
clipView.translatesAutoresizingMaskIntoConstraints = false

clipView.drawsBackground = false
scrollView.contentView = clipView

activate(
clipView.anchor.edges.equal.to(scrollView.anchor)
)

scrollView.documentView = stackView
stackView.translatesAutoresizingMaskIntoConstraints = false
activate(
clipView.anchor.left.top.right.equal.to(stackView.anchor)
)
}
}

Read more

Comments