// // ActivityIndicatorView.m // DGActivityIndicatorExample // // Created by 小花 on 2018/11/1. // Copyright © 2018年 Danil Gontovnik. All rights reserved. // #import "ActivityIndicatorView.h" #import "ActivityIndicatorAnimation.h" static ActivityIndicatorView *_indicatorView = nil; @implementation ActivityIndicatorView + (instancetype)shareIndicatorView { static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ _indicatorView = [[ActivityIndicatorView alloc] initWithTintColor:@[[UIColor YHColorWithHex:0xFE6461],[UIColor YHColorWithHex:0xFFE000],[UIColor YHColorWithHex:0x66D8FF]] size:50]; _indicatorView.frame = CGRectMake(0, 0, 100 , 100) ; }); return _indicatorView; } - (id)initWithTintColor:(NSArray *)tintColors size:(CGFloat)size { self = [super init]; if (self) { _size = size; _tintColors = tintColors; } return self; } + (instancetype)showInView:(UIView *)superView frame:(CGRect)frame { ActivityIndicatorView *indicatorView = [[ActivityIndicatorView alloc] initWithTintColor:@[[UIColor YHColorWithHex:0xFE6461],[UIColor YHColorWithHex:0xFFE000],[UIColor YHColorWithHex:0x66D8FF]] size:50]; indicatorView.frame = frame; indicatorView.backgroundColor = [UIColor whiteColor]; [indicatorView startAnimating]; [superView addSubview:indicatorView]; return indicatorView; } #pragma mark - #pragma mark Methods - (void)setupAnimation { self.layer.sublayers = nil; ActivityIndicatorAnimation *animation = [[ActivityIndicatorAnimation alloc] init]; [animation setupAnimationInLayer:self.layer withSize:CGSizeMake(_size, _size) tintColor:_tintColors]; self.layer.speed = 0.0f; } - (void)startAnimating { if (!self.layer.sublayers) { [self setupAnimation]; } self.layer.speed = 1.0f; _animating = YES; } - (void)stopAnimating { self.layer.speed = 0.0f; [self removeFromSuperview]; _animating = NO; } @end