LoadingView.m
1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//
// 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