Course info
Aug 8, 2016
1h 12m

One of the most exciting and necessary tools to know when developing for iOS is how to customize the controls inside UIKit. In this course, Creating Custom Controls in iOS, you'll do more than just walk through how to make custom controls, you'll start at the very beginning - with a blank slate. First, you'll learn about classes to use. Then, you'll learn all about passing data back and forth. Finally, you'll gain experience in animating your controls. After this course, you'll have the knowledge and experience to start making any controls you could possibly imagine.

About the author
About the author

Jordan Morgan is a software developer from Ozark, Missouri, who founded Dreaming In Binary with his wife. He is focused on helping the community, creating things that inspire others, doing talks over iOS, and constantly being a student of any form of software engineering.

More from the author
Implementing 3D Touch in iOS
1h 22m
Nov 2, 2016
Section Introduction Transcripts
Section Introduction Transcripts

Course Overview
Hello and welcome to Creating Custom Controls for iOS. My name is Jordan Morgan, and I'm thrilled to teach you about one of the most exciting and necessary tools of any iOS developer skillset. Having been a professional iOS developer for several years now, I can't even count the number of times I've had to tweak some of UIKit's controls, or needed to create something entirely custom from the ground up. But, if you're relatively new to the field, this can be a massive undertaking, but it doesn't have to be. If you've ever wanted to make a customized control is iOS, but just kind of immediately stopped in your tracks by not knowing which classes to inherit from, which methods to override, and how to make it work with auto layout or frame setting, this is absolutely where you want to be. This course is not just a simple walkthrough on how to make custom controls, we're starting from the absolute beginning here with a blank slate, and we aren't stopping until we've made a full custom control by the end. We're going to cover everything here too, such as which classes to use, how to pass data back and forth, and how to animate your control, plus I've made sure to cover all the routes, from using Interface Builder, to a pure programmatic approach, to talking about how to pass data using delegation or closures, it's all covered right here. Not only that, but I'll make sure that you leave with all of the best practices too, and I'll give you plenty of advice on how to get inspired for your next awesome project. So, if you're young in your iOS career and want to get started with making your own custom controls, you are in the perfect spot, and I can't wait to show you how.

Hi, I'm Jordan Morgan, and welcome to Creating Custom Controls in iOS. If you've ever picked up an app and saw that nifty animated button, or were wowed by some slick navigation and wondered how do I do that, then you're in the right spot. Here we're going to get our feet wet with building some custom controls, things that aren't stock or included inside of Apple's UIKit. In our case, we'll be building out a custom control that does some fun, contextual animations, and text entry for a login form. You see this scenario all over the place now, right? What app is out there that isn't connected, and that doesn't require some sort of log in? They're all over, so we'll take this common flow and spruce it up a bit with a custom control built from scratch. So, if you want to build your own custom controls and have no idea where to start, this is exactly where you need to be. If you've ever thought, do I need to build it and only work with frames or auto layout, should it work it storyboards, or will it need to be initialized programmatically, we're going to tackle all of those topics and more as we start from the very beginning and build out our control through to the end. So, sit back, boot up your Mac, and let's get going.

Creating the UI
Welcome to module 2 of Creating Custom Controls in iOS. Here, we're going to get busy, and build out most of the user interface for our control. While it won't do much, after we're done we will have laid all of the ground work to finish up our control. When it comes to making these controls, there really are two central aspects of the whole process. The first is creating the outward facing components, and the second is hooking it up and making it do things. The tricky thing is a lot of new iOS developers seem to get stuck asking too many questions about this first part. They hit that wall of resistance brought on by questions like should I work with auto layout, or just frames? Wait, is that even a valid question, what do I need to override? Do I even need to override anything? Hmm, what about storyboard support too? And those are all great questions, believe me, I had the same ones. After several years of doing this though, I found if you just follow Apple's examples, most of those questions aren't as relevant as you may have initially thought. For instance, we can still provide pixel perfect frames within our control, and still support auto layout. In fact, we'll even do that in this very course. The same goes for storyboards versus code. We can easily set things up to make our control play nice when it's initialized programmatically, just as well as when it's being used on a storyboard. We'll talk about how to do this too, and you'll see that the way controls are created with an iOS is actually surprisingly simple. Apple realizes that there are just as many developers who write entire apps in code, just as there are developers who live by NIB files and storyboards, so they made it to where it's easy to use either or, and use the two in harmony. That said, there are some technical things to keep in mind when creating these controls. And when I began thinking about this course and trying to distill it down to the pure basic concepts, I realized there's really one central place to start, and that is which class should you inherit from to create your control? There are a few options, but to understand which to choose, we need to know what they do and how they work. In the next clip, we'll cover those important concepts.

Communicating with View Controllers
Okay, at this point we've done some really meaningful work, but we're only half way there. Our control has almost all of its UI built, and it has some animations and so forth, but there are some communication we need to create between it and the control's owner. We're going to talk about how to create that bridge of communication in this module, and rightfully so, as there are several ways to go about it. Now, let's think about what we actually have to communicate here. Our control is made flexible, it can represent either a password or an email address field. Looking at those two, the email field seems like something we can make a bit more assumptions about. For instance, we made our control check if the email was valid or not, because typically, an email is an email is an email, right? The password on the other hand, I think that's a bit more abstract. There could be a few rules on what a correct password is, if it's even needed, and more, so it doesn't really make much sense, I think, for our control to do any validation against it internally. We can let the owner do that however they want. So, given that, how can we communicate back to our control's owner, typically a view controller, that the email is valid or it's not valid? How do we connect the two? If our control can't tell anyone if the supplied email address is valid or not, then it's not going to be doing us much good. So let's head over to the next clip and I'll lay out the ways that we can go about this.