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 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
|
#import "HJStatusBarHUD.h"
#define DEFAULT_HEIGHT 44.0f
@implementation HJStatusBarHUD
- (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { self.contentMode = UIViewContentModeCenter; self.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin; self.opaque = NO; self.backgroundColor = [UIColor clearColor]; [self addSubview:self.textLabel]; } return self; }
- (NSString *)text { return _textLabel.text; }
- (void)setText:(NSString *)text { _textLabel.text = text; }
- (UILabel *)textLabel { if(_textLabel == nil) { UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.bounds.size.width,self.bounds.size.height)]; label.textAlignment = NSTextAlignmentCenter; label.adjustsFontSizeToFitWidth = YES; label.textColor = [UIColor whiteColor]; _textLabel =label; } return _textLabel; }
- (void)dealloc { _textLabel=nil; }
+(instancetype)statusBarHUD { return [[self alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, DEFAULT_HEIGHT)]; }
+(void)showTips:(UIViewController *)controller withText:(NSString *)text Duration:(NSTimeInterval)duration; { CGRect frame=CGRectMake(0, 0, controller.view.bounds.size.width,DEFAULT_HEIGHT); HJStatusBarHUD * HUD=[HJStatusBarHUD statusBarHUD]; if([controller.parentViewController isKindOfClass:[UINavigationController class]] && !controller.navigationController.navigationBar.isHidden){ frame.origin.y = controller.navigationController.navigationBar.height+20-DEFAULT_HEIGHT; HUD.frame=frame; [controller.navigationController.view insertSubview:HUD belowSubview:controller.navigationController.navigationBar]; }else{ frame.origin.y = 20-DEFAULT_HEIGHT; HUD.frame=frame; [controller.view addSubview:HUD]; } HUD.text = text; HUD.backgroundColor=[UIColor orangeColor]; [HJStatusBarHUD showHUB:HUD Duration:duration]; }
+(void)showTips:(UIViewController *)controller withText:(NSString *)text; { [self showTips:controller withText:text Duration:0.75]; }
+(void)showHUB:(HJStatusBarHUD *)StatusBarHUD Duration:(NSTimeInterval)duration { [UIView animateWithDuration:duration animations:^{ StatusBarHUD.transform = CGAffineTransformMakeTranslation(0, StatusBarHUD.height); } completion:^(BOOL finished) { CGFloat delay = 1.0; [UIView animateWithDuration:duration delay:delay options:UIViewAnimationOptionCurveEaseInOut animations:^{ StatusBarHUD.transform = CGAffineTransformIdentity; } completion:^(BOOL finished) { [StatusBarHUD removeFromSuperview]; }]; }];
} @end
|