MONActivityIndicatorView 是一个用于 iOS 的出色的自定义活动指示器视图。
MONActivityIndicatorView.h
和 MONActivityIndicatorView.m
添加到您的项目中。import MONActivityIndicatorView.h
- (void)viewDidLoad {
[super viewDidLoad];
MONActivityIndicatorView *indicatorView = [[MONActivityIndicatorView alloc] init];
[self.view addSubview:indicatorView];
}
[indicatorView startAnimating];
[indicatorView stopAnimating];
delay = 0.2
duration = 0.8
numberOfCircles = 5
radius = 10
internalSpacing = 5
defaultColor = [UIColor lightGrayColor]
- (void)viewDidLoad {
[super viewDidLoad];
MONActivityIndicatorView *indicatorView = [[MONActivityIndicatorView alloc] init];
indicatorView.numberOfCircles = 3;
indicatorView.radius = 20;
indicatorView.internalSpacing = 3;
indicatorView.duration = 0.5;
indicatorView.delay = 0.5
indicatorView.center = self.view.center;
[self.view addSubview:indicatorView];
[indicatorView startAnimating];
}
首先,将 MONActivityIndicatorViewDelegate
协议分配给一个视图控制器。然后,实现方法 activityIndicatorView:circleBackgroundColorAtIndex:
@interface ViewController : UIViewController <MONActivityIndicatorViewDelegate>
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
MONActivityIndicatorView *indicatorView = [[MONActivityIndicatorView alloc] init];
indicatorView.delegate = self;
indicatorView.numberOfCircles = 3;
indicatorView.radius = 20;
indicatorView.internalSpacing = 3;
indicatorView.duration = 0.5;
indicatorView.delay = 0.5
indicatorView.center = self.view.center;
[self.view addSubview:indicatorView];
[indicatorView startAnimating];
}
- (UIColor *)activityIndicatorView:(MONActivityIndicatorView *)activityIndicatorView
circleBackgroundColorAtIndex:(NSUInteger)index {
// For a random background color for a particular circle
CGFloat red = (arc4random() % 256)/255.0;
CGFloat green = (arc4random() % 256)/255.0;
CGFloat blue = (arc4random() % 256)/255.0;
CGFloat alpha = 1.0f;
return [UIColor colorWithRed:red green:green blue:blue alpha:alpha];
}
@end