1,將下載好的第3方類庫MBprogressHUD源碼包加入到工程(其實就是一個.h和.m文件)
2,進入工程的Build Phases,將源碼包裡面的所有.m文件全部添加到工程
3,添加第3方類庫的主頭文件"MBProgressHUD.h"
顯示代碼:
// 一開始加載就,顯示提示條
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:webView animated:YES];
// 加一層蒙版
hud.dimBackground = YES;
hud.labelText = @"頁面加載中...";隱藏代碼:
// 一旦加載完畢,就隱藏提示條
[MBProgressHUD hideAllHUDsForView:webView animated:YES];// 抽取的,僅供分類內部調用
+ (void) showMsg:(NSString *)msg imgName:(NSString *)imgName
{
// 顯示到主窗口中
MBProgressHUD *hud =[MBProgressHUD showHUDAddedTo:[UIApplication sharedApplication].keyWindow animated:YES];
// 顯示模式,改成customView,即顯示自定義圖片(mode設置,必須寫在customView賦值之前)
hud.mode = MBProgressHUDModeCustomView;
int delay = 1;
if ([imgName isEqualToString:@"error.png"]) {
// 錯誤時,提示3秒鐘
delay = 3;
}
imgName = [NSString stringWithFormat:@"MBProgressHUD.bundle/%@",imgName];
// 設置要顯示 的自定義的圖片
hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:imgName]];
// 顯示的文字,比如:加載失敗...加載中...
hud.labelText = msg;
// 標志:必須為YES,才可以隱藏, 隱藏的時候從父控件中移除
hud.removeFromSuperViewOnHide = YES;
// 3秒後自動隱藏
log(@"%d",delay);
[hud hide:YES afterDelay:delay];
}
其他常用屬性// 提示框的背景色 hud.color = [UIColor clearColor];//這兒表示無背景 // 提示下文的小文字 hud.detailsLabelText = @"detail"; // 陰影遮罩效果 hud.dimBackground = YES; // 1秒之後隱藏 [hud hide:YES afterDelay:1]; //只顯示文字 hud.mode = MBProgressHUDModeText; // 外邊距 和 Y方向偏移 hud.margin = 0; hud.yOffset = 0; // 隱藏後從父控件中移除 hud.removeFromSuperViewOnHide = YES; //圓形進度條 hud.mode = MBProgressHUDModeAnnularDeterminate;