Homework 6: Control Arc with a slider

In this assignment, you’ll use the Hacking with Swift website to learn how sliders work in SwiftUI, then apply that knowledge to build two interactive drawing exercises.

Before You Begin

Read through the Hacking with Swift slider lesson and study the code sample. Understanding how to create a slider and read its value is the foundation for both parts below.

Part 1: Arc with a Slider

  1. Create an arc shape and a slider that controls the arc’s size. As you slide in one direction, the arc should grow; in the other, it should shrink.
  2. Add a text field that displays the current value of the slider.
  3. Extra challenge: Display the value as a whole number rather than a decimal. Hint: wrap the slider value in Int() to convert it from a Double to an integer before displaying it.

Part 1 Demo

Video: A screen recording of the iOS Simulator showing a slider and an arc shape. Dragging the slider left or right increases or decreases the arc’s sweep angle in real time.

Part 2: Progress Indicator

Now that you’ve built an arc controlled by a slider, create a new SwiftUI file and build a progress indicator that’s also controlled by a slider.

Hint: Reuse your arc code from the textbook as a starting point for the progress indicator shape.

Part 2 Demo

Video: A screen recording of the iOS Simulator showing a circular progress indicator ring and a slider. As the slider value changes, the ring fills proportionally to represent the current progress.