Top Tabs in SwiftUI
Reading time: 1 min
This tutorial shows how to add Android-like top tabs in SwiftUI. The result will look something like this:
Without much ado, here's the code for the component:
struct Tabs: View {
@Binding var tabs: [String] // The tab titles
@Binding var selection: Int // Currently selected...
SVG images in SwiftUI
Reading time: 1 min
This tutorial shows how to use SVG images in SwiftUI.
First, add the Macaw library to your project. Then, wrap its SVGView
using this simple UIViewRepresentable
wrapper:
import Macaw
struct SVGImage: UIViewRepresentable {
// a binding allows for dynamic updates to the shown image
@B...
Focus change in TextField and SecureField
Reading time: 2 min
Detecting if a text field gained or lost focus is not entirely straightforward in SwiftUI.
TextField
constructor has a parameter named onEditingChanged
, but it triggers only when the user taps the return key in the virtual keyboard, not when the focus is actually lost.
Even worse, SecureFi...
Reading time: 1 min
This tutorial shows how to create a custom Swiftui Button style with distinct disabled and pressed states. The end result will look like this:
Default | Pressed | Disabled |
---|---|---|
![]() |
![]() |
![]() |
Let's get down to business! First, define three colors that represent the default and disabled state. Also throw i...
Reading time: 1 min
A common issue in SwiftUI is that, when the keyboard appears, it covers up a part of your UI. This is especially problematic if it overlaps the exact TextField
you're editing, so that you can't even see what you're typing!
Take this credit card input field at the bottom of a screen:
If you o...