HKActivityRingView
HKActivityRingView
HKActivityRingView Class of HealthKitUI A view that uses the Move, Exercise, and Stand activity rings to display data from a HealthKit activity summary object.
class HKActivityRingViewOverview
Use HKActivityRingView to display data from an HKActivitySummary object. For example, the following image shows how the rings can display a summary view of a person’s activity.
[Two partially filled and one completely filled colored concentric rings on a black background.]
To display activity summary data from the HealthKit store, use an HKActivitySummaryQuery object. You can also instantiate and display your own HKActivitySummary objects, as needed.
The activity ring view always appears as a black rectangle with colored concentric rings. The rings are centered in the view and are sized to fit the available space.
[Two partially filled and one completely filled colored concentric rings centered on a black rectangle background.]
The activity ring view displays different rings depending on the properties defined in the ring view’s HKActivitySummary property. When the view’s HKActivitySummary has activityMoveMode set to appleMoveTime and nil values for appleExerciseTimeGoal and appleStandHoursGoal the ring only displays the red Move ring. Otherwise, it displays the Move, Exercise, and Stand activity as red, green, and blue concentric rings. Summary data from the HealthKit store only displays the Move ring when the person hasn’t paired an Apple Watch.
The rings can display as either empty or with a dot at the top of the ring to display a lack of data. Empty rings indicate that the activity summary is missing, and a dot at the top indicates that the activity summary’s values are set to zero.
If the ring has a nil-valued activitySummary quantity properties, the rings appear empty. Use this to indicate that there is no summary data available for the specified day. For example, dates in the future.
[Three dimly colored concentric rings.]
If the summary has zero-valued quantities set for its value properties, the ring displays a dot at the top of the ring. Use this to indicate that the person hasn’t burned any active calories, exercised, or earned any stand hours for the specified day.
[Three dimly colored concentric rings with a bright dot at the top of each ring.]
To display data for a ring, the HKActivitySummary object must have a non-nil quantity for both the corresponding value property and the goal property.
|Ring |Value property |Goal property | |--------|------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------| |Move |`doc://com.apple.healthkit/documentation/HealthKit/HKActivitySummary/activeEnergyBurned|doc://com.apple.healthkit/documentation/HealthKit/HKActivitySummary/activeEnergyBurnedGoal| |Exercise|doc://com.apple.healthkit/documentation/HealthKit/HKActivitySummary/appleExerciseTime |doc://com.apple.healthkit/documentation/HealthKit/HKActivitySummary/appleExerciseTimeGoal | |Stand |doc://com.apple.healthkit/documentation/HealthKit/HKActivitySummary/appleStandHours |doc://com.apple.healthkit/documentation/HealthKit/HKActivitySummary/appleStandHoursGoal` |
Move only ring properties:
|Ring|Value property |Goal property | |----|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| |Move|`doc://com.apple.healthkit/documentation/HealthKit/HKActivitySummary/appleMoveTime | doc://com.apple.healthkit/documentation/HealthKit/HKActivitySummary/activeEnergyBurned|doc://com.apple.healthkit/documentation/HealthKit/HKActivitySummary/appleMoveTimeGoal | doc://com.apple.healthkit/documentation/HealthKit/HKActivitySummary/activeEnergyBurnedGoal`|
The activity ring view colors a percentage of each ring based on these properties, as shown here:
ring percent = value property quantity / goal property quantity[One partially filled colored concentric ring on a black background.]
The following code snippet shows how to manually display only the Move ring:
let moveOnlySummary = HKActivitySummary()
moveOnlySummary.activityMoveMode = .appleMoveTime
moveOnlySummary.appleMoveTime = HKQuantity(unit: .minute(), doubleValue: 60.0)
moveOnlySummary.appleMoveTimeGoal = HKQuantity(unit: .minute(), doubleValue: 90.0)