Introduction
A loader is something in a service based app for loading data from the server, it takes time to download heavy data such as audio, images and so on. For a better user experience developers show an activity view until the download completes.
The following is the procedure to create and use it in an application.
Step 1
Open XCode by double-clicking on it.
Step 2
Create a UIView class like the following.
Step 3
Take User Interface View like the following:
Step 4
Now here we will write the code in the UIView class Objective-C file.
BActivityIndicator.h
- #import < UIKit / UIKit.h >
-
- @interface BActivityIndicator: UIView {
- CGAffineTransform rotationTransform;
- }@property(weak, nonatomic) IBOutlet UILabel * pleaseWaitLabel;@property(weak, nonatomic) IBOutlet UIImageView * spinningImage;
-
- - (id) initWithView: (UIView * ) view;
-
- + (BActivityIndicator * ) showHUDAddedTo: (UIView * ) view animated: (BOOL) animated;
-
- + (BOOL) hideHUDForView: (UIView * ) view animated: (BOOL) animated;
-
- @end
BActivityIndicator.m
ViewController.Xib
Step 7
Now here I’ll explain how to call that class within a project.
In your common Utility Class you need to write these functions for calling it:
- #pragma mark - Activity Indicator + (void) startActivityIndicatorInView: (UIView * ) aView withMessage: (NSString * ) aMessage {
-
-
-
-
- BActivityIndicator * _hud = [BActivityIndicator showHUDAddedTo: aView animated: YES];
-
-
- }
-
- + (void) stopActivityIndicatorInView: (UIView * ) aView {
-
- [BActivityIndicator hideHUDForView: aView animated: YES];
- }
Output