| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- //
- // FanweCustomHud.m
- // BuguLive
- //
- // Created by xfg on 2017/3/9.
- // Copyright © 2017年 xfg. All rights reserved.
- //
- #import "FanweCustomHud.h"
- @interface FanweCustomHud()
- {
- UIView * _loadingBackground; // 加载中的背景
- UIImageView * _loadingImageView; // 加载中的背景图
- UITextView * _textView;
- }
- @end
- @implementation FanweCustomHud
- static id _instance;
- + (instancetype)allocWithZone:(struct _NSZone *)zone
- {
- static dispatch_once_t onceToken;
- dispatch_once(&onceToken, ^{
- _instance = [super allocWithZone:zone];
- [_instance initMyData];
- });
- return _instance;
- }
- + (instancetype)sharedInstance
- {
- static dispatch_once_t onceToken;
- dispatch_once(&onceToken, ^{
- _instance = [[self alloc] init];
- [_instance initMyData];
- });
- return _instance;
- }
- - (id)copyWithZone:(NSZone *)zone
- {
- return _instance;
- }
- - (id)mutableCopyWithZone:(NSZone *)zone
- {
- return _instance;
- }
- - (void)initMyData
- {
- if (_loadingBackground == nil)
- {
- _loadingBackground = [[UIView alloc] init];
- _loadingBackground.hidden = YES;
- _loadingBackground.backgroundColor = kClearColor;
- _loadingBackground.alpha = 0.5;
-
- _textView = [[UITextView alloc]init];
- _textView.textAlignment = NSTextAlignmentCenter;
- _textView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
- _textView.textColor = [UIColor blackColor];
- _textView.hidden = YES;
- }
-
- if (_loadingImageView == nil)
- {
- float width = 50;
- float height = 50;
- NSMutableArray *array = [[NSMutableArray alloc] initWithObjects:[UIImage imageNamed:@"loading_image0.png"],
- [UIImage imageNamed:@"loading_image1.png"],
- [UIImage imageNamed:@"loading_image2.png"],
- [UIImage imageNamed:@"loading_image3.png"],
- [UIImage imageNamed:@"loading_image4.png"],
- [UIImage imageNamed:@"loading_image5.png"],
- [UIImage imageNamed:@"loading_image6.png"],
- [UIImage imageNamed:@"loading_image7.png"],
- [UIImage imageNamed:@"loading_image8.png"],
- [UIImage imageNamed:@"loading_image9.png"],
- [UIImage imageNamed:@"loading_image10.png"],
- [UIImage imageNamed:@"loading_image11.png"],
- [UIImage imageNamed:@"loading_image12.png"],
- [UIImage imageNamed:@"loading_image13.png"],
- [UIImage imageNamed:@"loading_image14.png"],
- nil];
- _loadingImageView = [[UIImageView alloc] init];
- _loadingImageView.bounds = CGRectMake(0, 0, width, height);
- _loadingImageView.animationImages = array;
- _loadingImageView.animationDuration = 1;
- _loadingImageView.hidden = YES;
- }
- }
- - (void)startLoadingInView:(UIView*)view tipMsg:(NSString *)tipMsg
- {
- CGRect rect = view.frame;
-
- if (_loadingBackground)
- {
- _loadingBackground.frame = CGRectMake(0, 0, CGRectGetWidth(rect), CGRectGetHeight(rect));
- [view addSubview:_loadingBackground];
- _loadingBackground.hidden = NO;
-
- _textView.bounds = CGRectMake(0, 0, CGRectGetWidth(rect), 30);
- _textView.center = CGPointMake(CGRectGetWidth(rect) / 2, CGRectGetHeight(rect) / 2 - 30);
- [_loadingBackground addSubview:_textView];
-
- if (![BGUtils isBlankString:tipMsg])
- {
- _textView.text = tipMsg;
- _textView.hidden = NO;
- }
- else
- {
- _textView.hidden = YES;
- }
- }
-
- if (_loadingImageView)
- {
- _loadingImageView.center = CGPointMake(CGRectGetWidth(rect) / 2, CGRectGetHeight(rect) / 2);
- [view addSubview:_loadingImageView];
- _loadingImageView.hidden = NO;
- [_loadingImageView startAnimating];
- }
- }
- - (void)stopLoading
- {
- if (_loadingBackground)
- {
- _loadingBackground.hidden = YES;
- }
-
- if (_loadingImageView)
- {
- _loadingImageView.hidden = YES;
- [_loadingImageView stopAnimating];
- }
- }
- @end
|