iOS 提示框
推荐一个好用的iOS 提示框库
集成方式
pod 'MBProgressHUD', '~> 1.2.0'
或者直接将附件拖入项目内
导入#import "MBProgressHUD.h"
在这里顺便分享一下使用小技巧
我们可以将hud定义成宏 .
#pragma mark - hud 提示
/**
默认请求开始的hud
*/
#define HudShow MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];\
hud.label.text = NSLocalizedString(@"请求中...", @"HUD loading title");
/**
自定义title的请求开始hud
*/
#define HudShowStr(str) MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];\
hud.label.text = NSLocalizedString(str, @"HUD loading title");
/**
移除hud
*/
#define HudHidden [hud hideAnimated:YES];
/**
自定义title 的提示hud
*/
#define HudMessageStr(str) hud.mode = MBProgressHUDModeText;\
hud.label.text = NSLocalizedString(str, @"HUD message title"); [hud hideAnimated:YES afterDelay:1];\
/**
提示的hud .title来自json
*/
#define HudMessage hud.mode = MBProgressHUDModeText;\
hud.label.text = NSLocalizedString(@"根据需求传值例如取服务器json的某个值", @"HUD message title"); [hud hideAnimated:YES afterDelay:1];\
/**
请求错误时的hud
*/
#define HudError hud.mode = MBProgressHUDModeText;\
hud.label.text = NSLocalizedString(@"网络差", @"HUD message title"); \
[hud hideAnimated:YES afterDelay:1.f];
/**
alert效果的hud
*/
#define alertHudShow(str) MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];\
hud.mode = MBProgressHUDModeText;\
hud.label.text = NSLocalizedString(str, @"HUD message title"); [hud hideAnimated:YES afterDelay:1];\
/**
请求时错误才提示的hud
*/
#define RequestErrorHud MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];\
hud.mode = MBProgressHUDModeText;\
hud.label.text = NSLocalizedString(@"网络差", @"HUD message title"); [hud hideAnimated:YES afterDelay:1];\
源码下载: Hud.zip
常见问题及demo:点击这里