Reading time: 1 min
Here's a quick recipe for getting the key window, top or root View Controller, in a scene-based SwiftUI app:
extension UIApplication {
var currentKeyWindow: UIWindow? {
UIApplication.shared.connectedScenes
.filter { $0.activationState == .foregroundActive }
.map { $0 as? UIWind...
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...
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...
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...