Created
February 21, 2018 17:46
-
-
Save zenangst/62490ad5ff0200427476df2e559e61f6 to your computer and use it in GitHub Desktop.
How frames work on macOS - Example 2
This file contains hidden or 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 | |
class ContainerView: ColorView { | |
override var isFlipped: Bool { return true } | |
} | |
class ColorView: NSView { | |
required init(frame: CGRect, color: NSColor) { | |
super.init(frame: frame) | |
wantsLayer = true | |
layer?.backgroundColor = color.cgColor | |
} | |
required init?(coder decoder: NSCoder) { | |
fatalError("init(coder:) has not been implemented") | |
} | |
} | |
let containerFrame = CGRect(origin: .zero, | |
size: CGSize(width: 200, height: 200)) | |
let containerView = ContainerView(frame: containerFrame, | |
color: NSColor.blue.withAlphaComponent(0.25)) | |
let colorFrame = CGRect(origin: .zero, | |
size: CGSize(width: 50, height: 50)) | |
let colorView = ColorView(frame: colorFrame, | |
color: NSColor.green.withAlphaComponent(0.5)) | |
containerView.addSubview(colorView) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment