Member-only story
Wheel Picker View in SwiftUI
How to create a wheel menu, and get the user’s swipe direction

Start with the data you want to show in the wheel.
If you want to use the wheel as a color wheel, you can store the color value.
If you would like to use this as a menu with an image at the middle of the wheel, then you can add an image variable.
In this tutorial, I’m displaying numbers along the side of the wheel for the user to pick.
The user will need to swipe left or right to move the wheel. Create an enum for the possible moves you want to user to have.
Create a view and add the following variables inside.
radius
: the wheel’s radius. This value is changed later inside appearance after taking the wheel’s frame size from our parent view.direction
: keep the direction of the user’s swipe.choosenIndex
: store the user’s choice of value from the wheel.degree
: the rotation degree of the wheel and its internal views.array
: this is an array ofmyVal
; the struct we created above. The array is used to construct the internal views inside our wheel.- circle size: the value for the width and height of our circle.
Create a function to move the wheel to the next value inside our wheel in the direction of the user’s swipe.