Created
February 26, 2018 19:58
-
-
Save zenangst/66a4cbe0463b57e0c434cbfa61df48c8 to your computer and use it in GitHub Desktop.
How scroll views work on macOS - Example 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Cocoa | |
import PlaygroundSupport | |
let subviewFrame = CGRect(origin: .zero, | |
size: CGSize(width: 320, height: 640 * 4)) | |
let gradient = CAGradientLayer() | |
gradient.colors = [ | |
NSColor.blue.withAlphaComponent(0.2).cgColor, | |
NSColor.blue.withAlphaComponent(0.4).cgColor | |
] | |
gradient.frame = subviewFrame | |
let documentView = NSView(frame: subviewFrame) | |
documentView.wantsLayer = true | |
documentView.layer?.addSublayer(gradient) | |
let scrollViewFrame = CGRect(origin: .zero, | |
size: CGSize(width: 320, height: 640)) | |
let scrollView = NSScrollView(frame: scrollViewFrame) | |
scrollView.backgroundColor = NSColor.green.withAlphaComponent(0.2) | |
scrollView.documentView = documentView | |
scrollView.contentView.scroll(to: CGPoint(x: 0, y: subviewFrame.size.height)) | |
PlaygroundPage.current.liveView = scrollView |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment