Material Design progress indicators display the length of a process or express an unspecified wait time. There are two styles of progress indicators: linear and circular.
This component only provides the circular implementation. See Progress View for the linear implementation.
- Material Design guidelines: Progress & activity
- Class: MDCActivityIndicator
- Class: MDCActivityIndicatorTransition
- Protocol: MDCActivityIndicatorDelegate
- Enumeration: Enumerations
- Enumeration: MDCActivityIndicatorMode
MDCActivityIndicator
is a view that has two modes: indeterminate and determinate. Indeterminate
indicators express an unspecified wait time, while determinate indicators represent the length of a
process. Activity indicators are indeterminate by default.
Add the following to your Podfile
:
pod 'MaterialComponents/ActivityIndicator'
Then, run the following command:
pod install
To import the component:
import MaterialComponents.MaterialActivityIndicator
#import "MaterialActivityIndicator.h"
MDCActivityIndicator instances are indeterminate by default.
let activityIndicator = MDCActivityIndicator()
activityIndicator.sizeToFit()
view.addSubview(activityIndicator)
// To make the activity indicator appear:
activityIndicator.startAnimating()
// To make the activity indicator disappear:
activityIndicator.stopAnimating()
MDCActivityIndicator *activityIndicator = [[MDCActivityIndicator alloc] init];
[activityIndicator sizeToFit];
[view addSubview:activityIndicator];
// To make the activity indicator appear:
[activityIndicator startAnimating];
// To make the activity indicator disappear:
[activityIndicator stopAnimating];
MDCActivityIndicator instances can be shown as determinate by modifying the indicatorMode
property and setting a percentage progress with progress
. progress
must be set to a floating
point number between 0 and 1. Values beyond this range will be capped within the range.
Note: Activity indicators are hidden unless they are animating, even if the indicator is determinate progress.
let activityIndicator = MDCActivityIndicator()
activityIndicator.sizeToFit()
activityIndicator.indicatorMode = .determinate
activityIndicator.progress = 0.5
view.addSubview(activityIndicator)
// To make the activity indicator appear:
activityIndicator.startAnimating()
// To make the activity indicator disappear:
activityIndicator.stopAnimating()
MDCActivityIndicator *activityIndicator = [[MDCActivityIndicator alloc] init];
[activityIndicator sizeToFit];
activityIndicator.indicatorMode = MDCActivityIndicatorModeDeterminate;
activityIndicator.progress = 0.5;
[view addSubview:activityIndicator];
// To make the activity indicator appear:
[activityIndicator startAnimating];
// To make the activity indicator disappear:
[activityIndicator stopAnimating];
Indeterminate activity indicators support showing multiple colors via the cycleColors
API.
Consider using this property if your brand consists of more than one primary color.
let activityIndicator = MDCActivityIndicator()
activityIndicator.cycleColors = [.blue, .red, .green, .yellow]
MDCActivityIndicator *activityIndicator = [[MDCActivityIndicator alloc] init];
activityIndicator.cycleColors = @[ UIColor.blueColor,
UIColor.redColor,
UIColor.greenColor,
UIColor.yellowColor ];
You can theme an activity indicator with your app's color scheme using the ColorThemer extension.
You must first add the Color Themer extension to your project:
pod 'MaterialComponents/ActivityIndicator+ColorThemer'
Run pod install
again.
// Step 1: Import the ColorThemer extension
import MaterialComponents.MaterialActivityIndicator_ColorThemer
// Step 2: Create or get a color scheme
let colorScheme = MDCSemanticColorScheme()
// Step 3: Apply the color scheme to your component
MDCActivityIndicatorColorThemer.applySemanticColorScheme(colorScheme, to: activityIndicator)
// Step 1: Import the ColorThemer extension
#import "MaterialActivityIndicator+ColorThemer.h"
// Step 2: Create or get a color scheme
id<MDCColorScheming> colorScheme = [[MDCSemanticColorScheme alloc] initWithDefaults:MDCColorSchemeDefaultsMaterial201804];
// Step 3: Apply the color scheme to your component
[MDCActivityIndicatorColorThemer applySemanticColorScheme:colorScheme
toActivityIndicator:activityIndicator];