Expandable Button in SwiftUI

Create an animated expandable button using SwiftUI

Ale Patrón
The Startup

--

The expandable button we will be building.

Note: This tutorial is also available in video form on YouTube.

In a previous article, I showed you how to build an expandable button with Swift and UIKit. With SwiftUI gaining traction, I decided to share an updated article showing how we can implement this same functionality using SwiftUI.

Implementing custom views with SwiftUI is extremely simple, and we will leverage its power to build an expandable button that will look like the one below:

Animated expandable button.

Our buttons will simply need to be embedded in a VStack. Whenever the primary button is tapped, we will either show or hide the secondary buttons, signaled in the diagram below, depending on their current state.

--

--