LoadingView.m 1.92 KB
//
//  LoadingView.m
//  QNLiveStreamingDemo
//
//  Created by iOS on 17/4/7.
//  Copyright © 2017年 zhulin. All rights reserved.
//

#import "LoadingView.h"

@interface LoadingView ()

@property (nonatomic, strong) UIActivityIndicatorView *activityIndicator;

@end

@implementation LoadingView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self addSubview:self.activityIndicator];
        [self addSubview:self.retryBtn];
        [self.activityIndicator startAnimating];
        
    }
    return self;
}

- (void)startLoading
{
    [_activityIndicator startAnimating];
    _retryBtn.hidden = YES;
}

- (void)stopLoading
{
    [self.activityIndicator stopAnimating];
}

#pragma mark -
#pragma mark - getter
- (UIActivityIndicatorView *)activityIndicator
{
    if (!_activityIndicator) {
        _activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
        _activityIndicator.center = CGPointMake(self.bounds.size.width/2, self.bounds.size.height/2);
    }
    return _activityIndicator;
}

- (UIButton *)retryBtn
{
    if (!_retryBtn) {
        _retryBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _retryBtn.frame = CGRectMake(self.bounds.size.width/2-40, self.bounds.size.height/2-20, 80, 40);
        [_retryBtn setTitle:@"重试" forState:UIControlStateNormal];
        [_retryBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _retryBtn.hidden = YES;
        _retryBtn.layer.cornerRadius = 10;
        _retryBtn.layer.masksToBounds = YES;
        _retryBtn.layer.borderColor = [UIColor whiteColor].CGColor;
        _retryBtn.layer.borderWidth = 1;
    }
    return _retryBtn;
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end