Sometimes you need to create UI elements with code. This video shows how to do just that.
- [Instructor] Now that we've gone through many UI elements,…let's look at creating one of them in code.…The object that we'll create now is a UI switch.…To do that, let's go inside viewDidLoad…and create a switch,…so let switchView…equal UISwitch…and here we'll specify a frame, that's a CGRect.…Just press return on that, open up the parentheses,…choose the option that asks for X, Y, width,…and height of CGFloat type.…
Choose that and then specify the location…and size of the switch.…Let's go 10 for X, 100 for Y, this is from the top-left,…so 100 points down from the top-left.…For the width, 100, height, 100,…and then we'll add it to the screen,…view.addSubView and then pass in the switchView.…Let's run the application and see what it looks like.…
There's a switch and we can toggle it on and off.…Let's say we wanted to respond…to when the switch is toggled on and off.…Let's return to Xcode, close the application,…and then what we need to do is connect an action…to the switchView.…So, switchView.add…and we want to choose the one with target and action.…
- Alert controllers and actions
- Sliders, progress bars, and switches
- Creating UI elements with code
- Displaying web content with Safari view controllers and WKWebView
- Creating collection view controllers
- Creating tabbed apps
- Publishing your app with App Store Connect
Skill Level Beginner
1. Master Views
2. Display Web Content
3. Collection Views
4. Multiview Templates
Customize a table view cell4m 18s
5. Publish an App
Next steps3m 28s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.