#if TARGET_IPHONE_SIMULATOR
#import <objc/objc-runtime.h>
#else
#import <objc/runtime.h>
#import <objc/message.h>
#endif
类方法显示文本:
+ (MBProgressHUD *)showHUDAddedTo:(UIView *)view
labelText:(NSString *)text
detailsLabelText:(NSString *)detail
animated:(BOOL)animated
{
MBProgressHUD *hud = [[MBProgressHUDalloc] initWithView:view];
if (!text) {
hud.labelText = @"";
} else {
hud.labelText = text;
}
if (!detail) {
hud.detailsLabelText = @"";
} else {
hud.detailsLabelText = detail;
}
[view addSubview:hud];
[hud show:animated];
#if __has_feature(objc_arc)
return hud;
#else
return [hudautorelease];
#endif
}
自动隐藏:
void hideHUDExUIApplication(idself, SEL _cmd)
{
[MBProgressHUDhideHUDForView:[UIApplicationsharedApplication].keyWindow animated:YES];
}
+ (MBProgressHUD *)showHUDLabelText:(NSString *) text
detailsLabelText:(NSString *) detail
dismissAfter:(int) second
animated:(BOOL) animated
{
MBProgressHUD *hub = [MBProgressHUDshowHUDAddedTo:[UIApplicationsharedApplication].keyWindow
labelText:text detailsLabelText:detail animated:animated];
if (![[UIApplicationsharedApplication] respondsToSelector:@selector(hideHUDExUIApplication)]) {
class_addMethod([UIApplicationclass], @selector(hideHUDExUIApplication), (IMP)hideHUDExUIApplication,"v@:");
}
[[UIApplication sharedApplication] performSelector:@selector(hideHUDExUIApplication)withObject:nilafterDelay:second inModes:[NSArrayarrayWithObject:NSRunLoopCommonModes]];
return hub;
}