Beginner iOS Dev — Custom UIButtons — shadow buttons, toggle buttons, animated with frames , designable buttons, Lottie buttons, highlighted buttons…

James Tapping
7 min readMar 5, 2021

I recently put together a project as a reference for myself, a way of noting down difference techniques for building buttons.

The project uses various techniques, classes and extensions to achieve the above result. Obviously I can’t take credit for all of the code so I will credit where I can.

The project has been uploaded to GitHub, see below for link.

So starting from the top left … here we go.

Sound Toggle Button

This is a simple UIButton which uses two different images. All of the code can be found in SoundToggle.swift. It’s a subclass of UIButton, it’s very standard code, I can certainly credit Sean Allen for showing me the initial subclassing code :)

The images can be found in the standard assets folder.

The buttons state is handled with NSUserDefaults which has the advantage of keeping state even after the app has been restarted.

To set up the initial state(initial button image either on or off)I have added an extension, although this can easily be added to the class button init itself as is the case…

--

--