April 2015
Intermediate to advanced
556 pages
17h 47m
English
You will usually create your views in Interface Builder, but occasionally you will need to create views programmatically. If, for example, you have a pointer to a window and want to put a button on it, this code would create a button and put it on the window’s content view:
let superview = window.contentView let frame = NSRect(x: 10, y: 10, width: 200, height: 100) let button = NSButton(frame: frame) button.title = "Click me!" superview.addSubview(button)
Some of the Cocoa view classes are capable of a surprising variety of appearances. For example, you have no doubt seen that there are a lot of buttons in the object library. But there is only one NSButton class. All of the different button appearances ...