#import <UIKit/UIKit.h>
@interface SSLoading : UIView
- (instancetype)initWithFrame:(CGRect)frame;
- (void)showLoading:(UIColor *)backgroundColor alpha:(CGFloat)alpha;
-(void)disMiss;
@end
#import "SSLoading.h"
#import "UIImage+GIF.h"
@implementation SSLoading
{
UIView *SSLoadingBackView;
UIImageView *SSLoadingImageView;
}
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self.hidden = YES;
self.frame = frame;
}
return self;
}
- (void)showLoading:(UIColor *)backgroundColor alpha:(CGFloat)alpha
{
self.hidden = NO;
SSLoadingBackView = [[UIView alloc] initWithFrame:self.frame];
SSLoadingBackView.backgroundColor = backgroundColor;
SSLoadingBackView.alpha = alpha;
[self addSubview:SSLoadingBackView];
NSString *name = @"loading@2x.gif";
NSString *filePath = [[NSBundle bundleWithPath:[[NSBundle mainBundle] bundlePath]] pathForResource:name ofType:nil];
NSData *imageData = [NSData dataWithContentsOfFile:filePath];
if (!SSLoadingImageView) {
SSLoadingImageView = [[UIImageView alloc]init];
}
SSLoadingImageView.backgroundColor = [UIColor clearColor];
SSLoadingImageView.image = [UIImage sd_animatedGIFWithData:imageData];
SSLoadingImageView.frame = CGRectMake(self.frame.size.width/2-50, self.frame.size.height/2-50, 100, 100);
SSLoadingImageView.contentMode = UIViewContentModeScaleAspectFit;
[self addSubview:SSLoadingImageView];
}
-(void)disMiss
{
for (UIView *view in self.subviews) {
[view removeFromSuperview];
}
self.hidden = YES;
}