Learn SwiftUI: Pickers and Digital Crown

Unlike iPhones or iPads, watchOS has a rather unique way users can interact with apps – using the Digital Crown. In this post, we will revisit our Fahrenheit to Centigrade app and create a version of it for the Apple Watch using SwiftUI and learn how to use a Picker View and how the Digital Crown can work automatically for a Picker View – that is without needing to write explicit code for it.

The primary mechanism for receiving user input here is the Picker which helps you select a temperature from a pre-defined range of temperature values from 0°F to 140°F. You can do this by scrolling through the values using the touch screen.

But more interestingly, you can do the same by rotating the Digital Crown. This automatically scrolls through the entire list without us needing to do anything special. This shouldn’t be surprising since the watch allows us to scroll using the Digital Crown for most scenarios. In an upcoming post, we will explore more custom UI elements where we will use special modifiers on our SwiftUI Views so that the Digital Crown can interact with them.

Leave a Reply

Your email address will not be published. Required fields are marked *