From the course: iOS Development Tips

Unlock this course with a free trial

Join today to access over 23,200 courses taught by industry experts.

CALayer masks

CALayer masks

- [Instructor] UI doesn't have to look like a rectangle, you might want a different shape for your buttons, you can do that with layer masks. Let's learn how to set these up. Download the example files, if you go to the main storyboard you'll find an app with two square buttons, if you head over to the assets, you'll see that I have a thumb up and a thumb down icon, both regular and invert. Now the color here doesn't matter, as we'll talk about in a minute, head to the ViewController.swift code. I've already added the images from the assets folder here as constance. I've also created a function for you configureMask, which you can find down here, and we can get rid of this now. And that's where we'll add masks to buttons. A mask is an area, you know or in our case a CA layer, whose opacity determines visibility in an underlying layer. Areas that are solid appear where areas with an alpha of zero disappear. Masked layers are layers in CA layer and are CA layers themselves. So you're…

Contents