Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drawing rings with gradient similar to the Apple Watch fitness app

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:

  • Is there an API to create circular gradients in Core Graphics?
  • Is it possible to apply the gradient as the stroke color in Core Graphics?

Thanks

like image 763
user4781334 Avatar asked Apr 28 '15 05:04

user4781334


People also ask

What are the activity rings on the Apple Watch?

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.

Why do all Apple Watches track the same activity?

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.

What do the rings mean on the workout app?

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.

How much is the stand ring on the Apple Watch?

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.


1 Answers

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.

like image 145
ysnzlcn Avatar answered Oct 27 '22 16:10

ysnzlcn