Buttons can be created and used in code. Using code buttons requires some additional steps beyond what is used for labels and other, simpler UI items. See how to create buttons and connect them to actions in this tutorial.
- One thing it's important to know…is how to respond to actions in code.…In other words, when you create a button,…you want to be able to respond…to that button press with code,…so let's take a look at how that works here.…I've written some code already…to save us a little bit of time.…The code that I've written is code…that we've looked at already in this chapter.…So, I've created a label property, so we can use it later.…The label has a frame, some text,…it's added as a subview, and then I created a button…just like creating a label, except I used UIButton…instead of UILabel, the button…has a frame just like the label.…
I placed it a little bit below the label,…and then I add that as a subview.…I've also added some code called buttonWasTapped,…so it's a function, or method, that I created,…and it changes the text inside of the label to say, "Hello!"…So, the way that it should work…is when you tap the button, the text in the label…should change to say, "Hello!"…Watch what happens when we run the application.…I actually already have it running in the simulator,…
- Installing and using Xcode
- Working with storyboards
- Working with UI objects and events
- Resizing objects and layouts dynamically
- Coding UI objects such as buttons
- Loading and displaying data in table views
- Testing your iOS app
Skill Level Beginner
1. Xcode Fundamentals
2. Core Skills
3. Responsive UI Design
4. Coding UI Objects
5. Table Views
6. App Flow and Testing
Next steps1m 8s
- 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.