SwiftUI Delay Action on Appear
Reading time: 1 min
This recipe shows how to perform delayed actions in SwiftUI. It also shows examples of how to implement a delayed onAppear for async and non-async blocks. The end result looks like this:
There are two ways to delay actions in Swift in general:
- Using
DispatchQueue
withasyncAfter
with a...
SwiftUI Multiple Buttons in List Row
Reading time: 1 min
This quick recipe shows how to enable multiple Buttons in a List row. This is a long standing SwiftUI bug/quirk that fortunately has an easy workaround. Say you've put a few buttons in a List
row:
using code like this:
List {
HStack {
Button("First button") {
print("First actio...
Reading time: 2 min
This article is a cheatsheet for using system images/icons (SF Symbols) in SwiftUI. It shows all the ways to set their size, color and variants. The end results look like this:
Basics
System images or system icons refer to images that are present by default on Apple platforms. The image co...
SwiftUI Orientation Stack
Reading time: 1 min
This recipe shows how to implement an orientation stack in SwiftUI. This stack will lay out its content along the main screen axis - vertical or horizontal. In other words, it's a VStack
if your phone is in portrait mode and an HStack
if it's in landscape. The end result looks like this:
SwiftUI Device Orientation Change Observer
Reading time: 1 min
This recipe shows how to detect device orientation in SwiftUI. You can also use a binding to detect orientation changes. The end result looks like this:
The recipe relies on listening to UIDevice.orientationDidChangeNotification
notifications, which are automatically posted whenever device...