From the course: Cocoa with Swift 3 Essential Training
Unlock this course with a free trial
Join today to access over 22,400 courses taught by industry experts.
Code APIs for creating user interfaces
From the course: Cocoa with Swift 3 Essential Training
Code APIs for creating user interfaces
- [Narrator] Let's say you wanted to create some user interface elements with code. You're going to head over to AppDelegate.swift, and then hide the two areas on the left and the right, and go into applicationDidFinishLaunching. And here we're going to create a label. So here, we simply define a label, and we can set it equal to an NSTextField, and then we can call the constructor. And to create a label, all we need to do is pass in the constructor for labelWithString. So, we call this method, and then we pass in the string that we want for our label. Example label is fine. Now, what we need to do is put this label inside some sort of superview. So, if we got to the next line, we can type out window, that's our main window for our application, dot content view, if you look at the hint in here, it says the window's content view, the highest accessible NSView object in the window's view hierarchy. That's the same as that default view that we put everything in, when we use Interface…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.