Skip to content

Instantly share code, notes, and snippets.

View zenangst's full-sized avatar
🥪
Reminiscing about vacation

Christoffer Winterkvist zenangst

🥪
Reminiscing about vacation
View GitHub Profile
@zenangst
zenangst / Example1.swift
Created February 21, 2018 17:45
How frames work on macOS - Example 1
import Cocoa
class ContainerView: ColorView {}
class ColorView: NSView {
required init(frame: CGRect, color: NSColor) {
super.init(frame: frame)
wantsLayer = true
layer?.backgroundColor = color.cgColor
}
@zenangst
zenangst / Example2.swift
Created February 21, 2018 06:19
How to make a label in macOS - Example 2
import Cocoa
let label = NSTextField()
label.frame = CGRect(origin: .zero, size: CGSize(width: 100, height: 44))
label.stringValue = "My awesome label"
label.backgroundColor = .white
label.isBezeled = false
label.isEditable = false
label.sizeToFit()
@zenangst
zenangst / Example1.swift
Created February 18, 2018 11:09
How to make a label in macOS - Example 1
import UIKit
let label = UILabel()
label.frame = CGRect(origin: .zero, size: CGSize(width: 100, height: 44))
label.text = "My awesome label"
label.backgroundColor = .white
label.sizeToFit()
@zenangst
zenangst / Example3.swift
Created February 16, 2018 11:01
How to write an NSViewController without interface builder - Example 3
import Cocoa
class MyViewController: NSViewController {
override func loadView() {
self.view = NSView()
}
}
let frame = CGRect(origin: .zero, size: CGSize(width: 100, height: 100))
let viewController = MyViewController()
@zenangst
zenangst / Example2.swift
Created February 16, 2018 11:00
How to write an NSViewController without interface builder - Example 2
import Cocoa
class MyViewController: NSViewController {}
let frame = CGRect(origin: .zero, size: CGSize(width: 100, height: 100))
let viewController = MyViewController()
viewController.view.frame = frame
@zenangst
zenangst / Example1.swift
Created February 16, 2018 10:39
How to write an NSViewController without interface builder - Example 1
import UIKit
class MyViewController: UIViewController {}
let frame = CGRect(origin: .zero, size: CGSize(width: 100, height: 100))
let viewController = MyViewController()
viewController.view.frame = frame
@zenangst
zenangst / Example2.swift
Created February 16, 2018 07:17
Setting a background color to an NSView - macOS Example
import Cocoa
let frame = CGRect(origin: .zero, size: CGSize(width: 100, height: 100))
let view = NSView(frame: frame)
view.wantsLayer = true
view.layer?.backgroundColor = NSColor.blue.cgColor
@zenangst
zenangst / Example1.swift
Last active February 16, 2018 07:44
Setting a background color to an NSView - iOS Example
import UIKit
let frame = CGRect(origin: .zero, size: CGSize(width: 100, height: 100))
let view = UIView(frame: frame)
view.backgroundColor = UIColor.blue
@zenangst
zenangst / FamilyFrameworkExample3.swift
Created February 13, 2018 20:11
Why I wrote Family framework - Example 3
let familyController = FamilyViewController()
let customController = CustomViewController()
familyController.addChildViewController(customController, view: { $0.scrollView })
@zenangst
zenangst / FamilyFrameworkExample2.swift
Created February 13, 2018 20:10
Why I wrote Family framework - Example 2
let familyController = FamilyViewController()
let viewController = UIViewController()
familyController.addChildViewController(viewController, height: 175)