I am very new to Core Graphics, and I would like to know how it is possible to draw rings with gradients similar to the Apple Watch fitness app. I am trying to do this on an iOS app, as I think currently Core Graphics is not supported on WatchKit yet.
I found a very good tutorial on the following website to draw the rings.
http://makeapppie.com/2015/03/10/swift-swift-basic-core-graphics-for-the-ring-graph/
However I am trying to figure out how to add a gradient to the stroke color. So far based on what I have found there is no straight forward way to do this. In order to achieve this, I figured I need to find the answers to the following:
Thanks
If you don't know, Activity Rings have been a feature of the Activity app — which is now the "Fitness" app — since Apple released the first Apple Watch in 2015. And to be honest, the Activity Rings haven't changed much in the last five years.
This is because every Apple Watch has most of the same sensors that track fitness, including a built-in heart-rate sensor, GPS, gyroscope and altimeter. They all sync with Fitness and Health apps on your iPhone, and they all use Activity Rings to show you how you're progressing on your fitness goals throughout the day.
There are still three rings, each of represents a different fitness or movement goal that you should aim to achieve in one day. • The red Activity ring (aka your Move ring) represents your movement and shows you how many active calories you’ve burned.
The $9.99-per-month service offers guided workouts and cool down sessions led by a diverse team of coaches. The inner Apple Watch ring, the blue ring, is your Stand ring. Your Stand ring shows how many hours of the day you stood for at least one minute, with the goal of moving in at least 12 different hours.
You have must find the answer of your question for now but i will answer it for everyone trying to create same thing.
Firstly you need to create images from 1-100(naming them is importing so be careful with the names) to create ring animation. You can use this app in simulator to create ring images:
GitHub - WatchRingGenerator
After that you should import your animation images to your project(it doesn't matter if you import them in .xcassets or in folder but make sure your images target is your watch app not the watch app extention or the ios app)
After that you can create your animation like this:
override func awakeWithContext(context: AnyObject?){
super.awakeWithContext(context)
imageView.setImageNamed("ringImage-")
}
override func willActivate() {
imageView.startAnimatingWithImagesInRange(NSMakeRange(1, 46), duration: 1, repeatCount: 1)
//This code will animate the ring from ringImage-1 to ringImage-46
}
Hope it helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With