I need sample Xcode Swift code for a macOS app that shows the code for a Scroll View.
Here is a simplified code for viewDidLoad():
override func viewDidLoad() {
super.viewDidLoad()
let myDocView = NSView(frame: NSRect(x: 0, y: 0, width: 2000, height: 2000))
let ymax = Int(myDocView.frame.size.height)
for row in 1...9 {
for col in 1...9 {
let aButton = NSButton(frame: NSRect(x: col * 44 + 10, y: ymax - (row * 44 + 10), width: 32, height: 37))
aButton.title = row.description + "/" + col.description
myDocView.addSubview(aButton)
}
}
let arrayOfViews = self.view.subviews
print("arrayviews is \(arrayOfViews)")
let mySV = arrayOfViews[0] as! NSScrollView
print("ScrollView is \(mySV)")
mySV.scrollerStyle = .overlay
mySV.hasVerticalScroller = true
mySV.hasHorizontalScroller = true
mySV.autohidesScrollers = false
mySV.documentView = myDocView
}
Drag an NSScrollView from the library into the view in the storyboard and play with the constraints and view size.
I played with the constraints and size of the NSScrollView and found that I can add back all constraints and expand the Scrolll view to fill the main view. It will work; I don't understand how.