123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- //
- // UIViewController+HUB.m
- // ZhuDD
- //
- // Created by 张夏永 on 17/5/2.
- // Copyright © 2017年 ZXY. All rights reserved.
- //
- #import "UIViewController+HUB.h"
- #import "MBProgressHUD.h"
- #import <objc/runtime.h>
- @implementation UIViewController (HUB)
- static const void *HttpRequestHUDKey = &HttpRequestHUDKey;
- - (MBProgressHUD *)HUD{
- return objc_getAssociatedObject(self, HttpRequestHUDKey);
- }
- - (void)ShowHudInView:(UIView *)view hint:(NSString *)hint{
- [self HideHud];
- MBProgressHUD *HUD = [[MBProgressHUD alloc] initWithView:view];
- // HUD.backgroundView.userInteractionEnabled=NO;
- // HUD.userInteractionEnabled = NO;
- HUD.removeFromSuperViewOnHide=YES;
- HUD.bezelView.color=[UIColor blackColor];
- HUD.activityIndicatorColor=[UIColor whiteColor];
- HUD.label.text = hint;
- [view addSubview:HUD];
- [HUD showAnimated:YES];
- [self setHUD:HUD];
-
- }
- - (void)setHUD:(MBProgressHUD *)HUD{
- objc_setAssociatedObject(self, HttpRequestHUDKey, HUD, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
- }
- - (void)ShowReminder:(NSString *)reminder waitTime:(float)t with:(void (^)(void))block{
- [self HideHud];
- if (reminder.length==0) {
- return;
- }
- //显示提示信息
- UIView *view = [[UIApplication sharedApplication].delegate window];
- MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
- // Configure for text only and offset down
- hud.mode = MBProgressHUDModeText;
- hud.bezelView.color=[UIColor blackColor];
- hud.label.font=[UIFont systemFontOfSize:14];
- hud.label.textColor=[UIColor whiteColor];
- hud.label.text= reminder;
- hud.label.numberOfLines=0;
- hud.margin = 10.f;
- hud.removeFromSuperViewOnHide = YES;
-
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(t * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- [hud hideAnimated:YES];
- if(block){
- block();
- }
- });
- }
- -(void)ShowBadNetWork{
- [self HideHud];
- UIView *view = [[UIApplication sharedApplication].delegate window];
- MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
- hud.defaultMotionEffectsEnabled=YES;
- // Configure for text only and offset down
- hud.mode = MBProgressHUDModeText;
- hud.bezelView.color=[UIColor blackColor];
- hud.label.font=[UIFont systemFontOfSize:14];
- hud.label.textColor=[UIColor whiteColor];
- hud.label.text=@"网络不佳,请稍后重试";
- hud.margin = 10.f;
- hud.removeFromSuperViewOnHide = YES;
- [hud hideAnimated:YES afterDelay:1.5];
- }
- - (void)ShowHint:(NSString *)hint
- {
- [self HideHud];
- //显示提示信息
- UIView *view = [[UIApplication sharedApplication].delegate window];
-
- MBProgressHUD *HUD = [[MBProgressHUD alloc] initWithView:view];
- HUD.defaultMotionEffectsEnabled=YES;
- // HUD.backgroundView.userInteractionEnabled=NO;
- HUD.userInteractionEnabled=NO;
- HUD.bezelView.color=[UIColor blackColor];
- [UIActivityIndicatorView appearanceWhenContainedIn:[MBProgressHUD class], nil].color = [UIColor whiteColor];
- HUD.label.text = hint;
- HUD.label.textColor=[UIColor whiteColor];
- [view addSubview:HUD];
- [HUD showAnimated:YES];
- [HUD hideAnimated:YES afterDelay:15.0];
- [self setHUD:HUD];
-
- }
- - (void)ShowHint:(NSString *)hint vc:(UIViewController *)vc
- {
- [self HideHud];
- //显示提示信息
- UIView *view = vc.view;
-
- MBProgressHUD *HUD = [[MBProgressHUD alloc] initWithView:view];
- HUD.defaultMotionEffectsEnabled=YES;
- // HUD.userInteractionEnabled=YES;
- HUD.bezelView.color=[UIColor blackColor];
- [UIActivityIndicatorView appearanceWhenContainedIn:[MBProgressHUD class], nil].color = [UIColor whiteColor];
- HUD.label.text = hint;
- HUD.label.textColor=[UIColor whiteColor];
- [view addSubview:HUD];
- [HUD showAnimated:YES];
- [HUD hideAnimated:YES afterDelay:15.0];
- [self setHUD:HUD];
-
- }
- - (void)ShowHint:(NSString *)hint yOffset:(float)yOffset {
- //显示提示信息
- [self HideHud];
- UIView *view = [[UIApplication sharedApplication].delegate window];
- MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
- hud.defaultMotionEffectsEnabled=YES;
- // Configure for text only and offset down
- hud.mode = MBProgressHUDModeText;
- hud.label.text = hint;
-
- hud.label.font=[UIFont systemFontOfSize:14];
- hud.bezelView.color=[UIColor blackColor];
- hud.label.textColor=[UIColor whiteColor];
- hud.margin = 10.f;
- hud.offset=CGPointMake(hud.offset.x, hud.offset.y+yOffset);
- hud.removeFromSuperViewOnHide = YES;
- [hud hideAnimated:YES afterDelay:2.0];
-
-
- }
- - (void)HideHud {
-
- [[self HUD] removeFromSuperview];
-
- }
- - (void)hideWithMsg:(NSString *)msg After:(CGFloat)delay {
-
- //显示提示信息
- UIView *view = [[UIApplication sharedApplication].delegate window];
- [MBProgressHUD hideHUDForView:view animated:NO];
- MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
- hud.defaultMotionEffectsEnabled=YES;
- // Configure for text only and offset down
- hud.mode = MBProgressHUDModeText;
- hud.label.text = msg;
-
- hud.label.font=[UIFont systemFontOfSize:14];
- hud.bezelView.color=[UIColor blackColor];
- hud.label.textColor=[UIColor whiteColor];
- hud.margin = 10.f;
- hud.removeFromSuperViewOnHide = YES;
- [hud hideAnimated:YES afterDelay:delay];
- }
- @end
|