Scrolling ScrollView programatically
Reading time: 1 min
This recipe is about how to scroll a SwiftUI ScrollView
programatically. Here's a quick breakdown of what to do:
- For iOS 13 - tough luck - it can't be done. For whatever reason, this is one of things that were deemed less important for the initial release of SwiftUI.
- For iOS 14 and abov...
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...
Clip content in wrapped UITextField
Reading time: 1 min
When implementing a custom TextField
by wrapping a UITextField
in UIViewRepresentable
(just like we did in our custom SecureField that tracks focus change, you need to be careful as its size normally grows with its content. This can lead to the field spilling outside the bounds of its parent...
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...
Customize navigation bar button image
Reading time: 1 min
This tutorial shows how to customize the navigation bar buttons as images. It applies to both the back button, as well as the button on the right-hand side. The end result will look something like this:
To do so, use the navigationBarItems(leading:trailing)
method. As always, the navigation...