Why we are using UIActivity Indicator View ??
Displays an element that provides user feedback on the progress of a task or process with an unknown duration (to show the progress of a task with known duration, use UIProgressView instead). As long as the task or process continues, the activity indicator spins. A user does not interact with an activity indicator.
Output of example code show in below image
Programmatically create a UIActivity Indicator View
#import "ViewController.h"
@interface ViewController ()
{
UIActivityIndicatorView *activityIndicator;
}
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
activityIndicator.alpha = 1.0;
activityIndicator.center = CGPointMake(160, 360);
activityIndicator.hidesWhenStopped = NO;
[activityIndicator startAnimating];
[self.view addSubview:activityIndicator];
[self performSelector:@selector(stopActivity)withObject:nil afterDelay:5];
// This Activity indicator will stop after 5 seconds
}
-(void)stopActivity
{
[activityIndicator removeFromSuperview];
}
Below contents are from Apple Docs
Starting in iOS 5.0, you can set the color of the activity indicator by using the
Below contents are from Apple Docs
Overview
Use
an activity indicator to show that a task is in progress. An activity
indicator appears as a “gear” that is either spinning or stopped.
You control when an activity indicator animates by calling the startAnimating and stopAnimating methods. To automatically hide the activity indicator when animation stops, set the hidesWhenStopped property to YES.Starting in iOS 5.0, you can set the color of the activity indicator by using the
color property. Tasks
Initializing an Activity Indicator
Managing an Activity Indicator
Configuring the Activity Indicator Appearance
-
activityIndicatorViewStyleproperty -
colorproperty
Properties
activityIndicatorViewStyle
The basic appearance of the activity indicator.
@property UIActivityIndicatorViewStyle activityIndicatorViewStyle
Discussion
SeeUIActivityIndicatorStyle for the available styles. The default value is UIActivityIndicatorViewStyleWhite.Availability
- Available in iOS 2.0 and later.
Declared In
UIActivityIndicatorView.hcolor
The color of the activity indicator.
@property (readwrite, nonatomic, retain) UIColor *color
Discussion
If you set a color for an activity indicator, it overrides the color provided by theactivityIndicatorViewStyle property.Availability
- Available in iOS 5.0 and later.
Declared In
UIActivityIndicatorView.hhidesWhenStopped
A Boolean value that controls whether the receiver is hidden when the animation is stopped.
@property BOOL hidesWhenStopped
Discussion
If the value of this property isYES (the default), the receiver sets its hidden property (UIView) to YES when receiver is not animating. If the hidesWhenStopped property is NO, the receiver is not hidden when animation stops. You stop an animating progress indicator with the stopAnimating method.
Availability
- Available in iOS 2.0 and later.
Declared In
UIActivityIndicatorView.hInstance Methods
initWithActivityIndicatorStyle:
Initializes and returns an activity-indicator object.
- (id)initWithActivityIndicatorStyle:(UIActivityIndicatorViewStyle)style
Parameters
- style
- A constant that specifies the style of the object to be created. See
UIActivityIndicatorStylefor descriptions of the style constants.
Return Value
An initializedUIActivityIndicatorView object or nil if the object couldn’t be created.Discussion
UIActivityIndicatorView sizes the returned instance according to the specified style. You can set and retrieve the style of a activity indicator through the activityIndicatorViewStyle property.Availability
- Available in iOS 2.0 and later.
Declared In
UIActivityIndicatorView.hisAnimating
Returns whether the receiver is animating.
- (BOOL)isAnimating
Return Value
YES if the receiver is animating, otherwise NO.Availability
- Available in iOS 2.0 and later.
See Also
Declared In
UIActivityIndicatorView.hstartAnimating
Starts the animation of the progress indicator.
- (void)startAnimating
Discussion
When the progress indicator is animated, the gear spins to indicate indeterminate progress. The indicator is animated untilstopAnimating is called.Availability
- Available in iOS 2.0 and later.
Declared In
UIActivityIndicatorView.hstopAnimating
Stops the animation of the progress indicator.
- (void)stopAnimating
Discussion
Call this method to stop the animation of the progress indicator started with a call tostartAnimating. When animating is stopped, the indicator is hidden, unless hidesWhenStopped is NO.Availability
- Available in iOS 2.0 and later.
Declared In
UIActivityIndicatorView.hConstants
UIActivityIndicatorStyle
The visual style of the progress indicator.
typedef enum {
UIActivityIndicatorViewStyleWhiteLarge,
UIActivityIndicatorViewStyleWhite,
UIActivityIndicatorViewStyleGray,
} UIActivityIndicatorViewStyle;
Constants
UIActivityIndicatorViewStyleWhiteLarge- The large white style of indicator.
Available in iOS 2.0 and later.
Declared inUIActivityIndicatorView.h. UIActivityIndicatorViewStyleWhite- The standard white style of indicator (the default).
Available in iOS 2.0 and later.
Declared inUIActivityIndicatorView.h. UIActivityIndicatorViewStyleGray- The standard gray style of indicator.
Available in iOS 2.0 and later.
Declared inUIActivityIndicatorView.h.
Discussion
You set the value of theactivityIndicatorViewStyle property with these constants.Availability
- Available in iOS 2.0 and later.
Declared In
UIActivityIndicatorView.h

No comments:
Post a Comment