Activity indicators are visual indications of an app loading content. The Activity Indicator is a circular indicator that either rotates clockwise or fills to completion clockwise when displaying progress.
- Material Design guidelines: Progress & activity
- API: MDCActivityIndicator
- API: MDCActivityIndicatorMode
- API: MDCActivityIndicatorDelegate
When indicators are indeterminate they request that the user wait while something finishes when it's not necessary to indicate how long it will take.
When indicators are determinate they indicate how long an operation will take when the percentage complete is detectable.
- Xcode 7.0 or higher.
- iOS SDK version 7.0 or higher.
To add this component to your Xcode project using CocoaPods, add the following to your Podfile
:
pod 'MaterialComponents/ActivityIndicator'
Then, run the following command:
pod install
Progress and activity indicators are visual indications of an app loading content.
Before using Activity Indicator, you'll need to import it:
import MaterialComponents
#import "MaterialActivityIndicator.h"
Indeterminate indicators visualize an unspecified wait time.
Determinate indicators display how long an operation will take.
When indicators are indeterminate they request that the user wait while something finishes when it's not necessary to indicate how long it will take. This is the default mode and no additional parameters need to be set.
let activityIndicator = MDCActivityIndicator(frame: CGRect(x: 0, y: 0, width: 32, height: 32))
view.addSubview(activityIndicator)
// Start animation
activityIndicator.startAnimating()
...
// Stop animation
activityIndicator.stopAnimating()
MDCActivityIndicator *activityIndicator =
[[MDCActivityIndicator alloc] initWithFrame:CGRectMake(0, 0, 32, 32)];
[view addSubview:activityIndicator];
// Start animation
[activityIndicator startAnimating];
...
// Stop animation
[activityIndicator stopAnimating];
When indicators are determinate they indicate how long an operation will take when the percentage complete is detectable. The indicator mode must be set to determinate and a progress amount must be provided as a float in the range [0,1].
let activityIndicator = MDCActivityIndicator(frame: CGRect(x: 0, y: 0, width: 32, height: 32))
activityIndicator.indicatorMode = .determinate
activityIndicator.progress = 0.5
view.addSubview(activityIndicator)
// Start animation
activityIndicator.startAnimating()
...
// Stop animation
activityIndicator.stopAnimating()
MDCActivityIndicator *activityIndicator =
[[MDCActivityIndicator alloc] initWithFrame:CGRectMake(0, 0, 32, 32)];
activityIndicator.indicatorMode = MDCActivityIndicatorModeDeterminate;
activityIndicator.progress = 0.5;
[view addSubview:activityIndicator];
// Start animation
[activityIndicator startAnimating];
...
// Stop animation
[activityIndicator stopAnimating];