From the course: iOS Development Tips

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

Make a toggle button

Make a toggle button

- [Instructor] Sometimes you need a control that doesn't yet exist. For example, the UI switch control is far from customizable. I'd like a toggle switch that looks more like an old fashioned switch, or push button. Listen to the basics of making your own controls by making a UI button into a toggle button. So go ahead and open up the example file, you'll find an empty class UIToggleButton.swift, and go into there. Let me give myself some more room here. To make our toggle button, I'm going to subclass UI button, since much of what I want is there. I can't use an extension here because I'm going to add more properties, but the most important of those will be isOn. So we're gonna do var, isOn, colon, and that's a Bool, which will be false to start. And I'll just keep negating that back and forth to essentially give myself a toggle situation. Okay, very simple. No big deal. UI button subclasses UI control. There is a series of tracking methods in UI control that handle touches. For…

Contents