SwiftUI buttons and gradient

Overview

There are many tools in SwiftUI to make your buttons look any way you want them to, and this chapter leads you through the process of button creation and enhancement. It also shows how to create a ButtonStyle that works very similarly to a CSS rule in an html document. Instead of having to write lines on lines of code for each button, you can create a ButtonStyle instead. Super cool.

I hope you enjoy this lesson! If you ever go into this line of work, I’m certain that ButtonStyles will become part of your professional toolkit.

Read Chapter 6: Working with SwiftUI Buttons, Labels, and Gradient

Key Takeaways

  • A SwiftUI Button takes an action closure and a label — the label can be any view, not just text.
  • ButtonStyle works like a CSS class: define a style once, then apply it to many buttons with .buttonStyle().
  • SwiftUI offers three gradient types — LinearGradient, RadialGradient, and AngularGradient — any of which can fill a background or shape.
  • The Label view pairs text with an icon and automatically adapts its layout to context (toolbars, menus, lists, and standalone buttons).