1#import "EXAppLoadingCancelView.h" 2 3const NSTimeInterval kEXTimeUntilCancelAppears = 5.0f; 4 5@interface EXAppLoadingCancelView () 6 7@property (nonatomic, strong) UILabel *lblStatus; 8@property (nonatomic, strong) UILabel *lblAdvice; 9@property (nonatomic, strong) UIButton *btnCancel; 10@property (nonatomic, strong) NSTimer *tmrShowCancel; 11 12@end 13 14@implementation EXAppLoadingCancelView 15 16- (instancetype)init 17{ 18 if (self = [super init]) { 19 [self _setUpViews]; 20 } 21 return self; 22} 23 24- (void)dealloc 25{ 26 [self _invalidateTimer]; 27} 28 29- (void)setFrame:(CGRect)frame 30{ 31 [super setFrame:frame]; 32 _lblStatus.frame = CGRectMake(16.0f, 0, self.bounds.size.width - 32.0f, 24.0f); 33 _lblAdvice.frame = CGRectMake(_lblStatus.frame.origin.x, 0, _lblStatus.frame.size.width, CGFLOAT_MAX); 34 [_lblAdvice sizeToFit]; 35 _lblAdvice.center = CGPointMake(CGRectGetMidX(_lblAdvice.frame), CGRectGetMaxY(_lblStatus.frame) + CGRectGetMidY(_lblAdvice.frame) + 16.0f); 36 37 _btnCancel.frame = CGRectMake(0, 0, self.bounds.size.width - 48.0f, 36.0f); 38 _btnCancel.center = CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMaxY(_lblAdvice.frame) + 42.0f); 39} 40 41- (void)_setUpViews 42{ 43 self.backgroundColor = [UIColor clearColor]; 44 _lblStatus = [[UILabel alloc] init]; 45 _lblStatus.text = @"Opening project..."; 46 _lblStatus.font = [UIFont boldSystemFontOfSize:14.0f]; 47 _lblStatus.textColor = [UIColor blackColor]; 48 _lblStatus.textAlignment = NSTextAlignmentCenter; 49 [self addSubview:_lblStatus]; 50 51 _lblAdvice = [[UILabel alloc] init]; 52 _lblAdvice.text = @"This is taking much longer than it should. You might want to check your internet connectivity."; 53 _lblAdvice.numberOfLines = 0; 54 _lblAdvice.font = [UIFont systemFontOfSize:14.0f]; 55 _lblAdvice.textColor = [UIColor darkGrayColor]; 56 _lblAdvice.textAlignment = NSTextAlignmentCenter; 57 [self addSubview:_lblAdvice]; 58 59 _btnCancel = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 60 [_btnCancel setTitle:@"Go Back to Home" forState:UIControlStateNormal]; 61 _btnCancel.titleLabel.font = [UIFont boldSystemFontOfSize:14.0f]; 62 [_btnCancel setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal]; 63 _btnCancel.layer.borderWidth = 1.0f; 64 _btnCancel.layer.borderColor = [UIColor darkGrayColor].CGColor; 65 _btnCancel.layer.cornerRadius = 3.0f; 66 [_btnCancel addTarget:self action:@selector(_onTapCancel) forControlEvents:UIControlEventTouchUpInside]; 67 [self addSubview:_btnCancel]; 68 69 _lblAdvice.hidden = YES; 70 _btnCancel.hidden = YES; 71 _tmrShowCancel = [NSTimer scheduledTimerWithTimeInterval:kEXTimeUntilCancelAppears 72 target:self 73 selector:@selector(_onCancelTimerFinished) 74 userInfo:nil repeats:NO]; 75 76 [self setNeedsLayout]; 77} 78 79- (void)_onTapCancel 80{ 81 if (_delegate) { 82 [_delegate appLoadingCancelViewDidCancel:self]; 83 } 84} 85 86#pragma mark - cancel timer 87 88- (void)_invalidateTimer 89{ 90 if (_tmrShowCancel) { 91 [_tmrShowCancel invalidate]; 92 _tmrShowCancel = nil; 93 } 94} 95 96- (void)_onCancelTimerFinished 97{ 98 [self _invalidateTimer]; 99 _lblAdvice.hidden = NO; 100 _btnCancel.hidden = NO; 101} 102 103@end 104