Created
April 4, 2025 04:26
-
-
Save kopyl/8307828347de4fee961603c62a97f059 to your computer and use it in GitHub Desktop.
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 ViewController: NSViewController { | |
| let items = Array(0..<3).map { String($0) } | |
| override func loadView() { | |
| self.view = NSView(frame: NSRect(x: 0, y: 0, width: 400, height: 300)) | |
| } | |
| override func viewDidLoad() { | |
| super.viewDidLoad() | |
| let stackView = NSStackView() | |
| stackView.orientation = .vertical | |
| stackView.alignment = .leading | |
| stackView.spacing = 4 | |
| stackView.translatesAutoresizingMaskIntoConstraints = false | |
| view.addSubview(stackView) | |
| for item in items { | |
| let textView = NSTextField(labelWithString: item) | |
| stackView.addArrangedSubview(textView) | |
| } | |
| NSLayoutConstraint.activate([ | |
| stackView.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 10), | |
| stackView.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -10), | |
| stackView.topAnchor.constraint(equalTo: view.topAnchor, constant: 10) | |
| ]) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment