代碼很簡單,羅列了三種類型辛孵,分別是默認(rèn)的菊花提示好啰、純文本提示、自定義視圖提示疑务。
默認(rèn)提示:
func defaultShow(){
var hud = MBProgressHUD.showHUDAddedTo(self.view, animated: true)
hud.labelText = "這是默認(rèn)帶菊花的提示"
//背景漸變效果
hud.dimBackground = true
//延遲隱藏
hud.hide(true, afterDelay: 0.8)
}
效果圖:
20150828222106_24533.png
純文本提示:
func textShow(){
var hud = MBProgressHUD.showHUDAddedTo(self.view, animated: true)
hud.mode = MBProgressHUDMode.Text
hud.labelText = "這是純文本提示"
hud.detailsLabelText = "這是詳細(xì)信息內(nèi)容沾凄,會很長很長呢"
//延遲隱藏
hud.hide(true, afterDelay: 0.8)
}
效果圖:
20150828222148_29935.png
自定義視圖提示:
func customShow(){
var hud = MBProgressHUD.showHUDAddedTo(self.view, animated: true)
hud.mode = MBProgressHUDMode.CustomView
hud.customView = UIImageView(image: UIImage(named: "yes")!)
hud.labelText = "這是自定義視圖"
//延遲隱藏
hud.hide(true, afterDelay: 0.8)
}
效果圖:
20150828222217_65570.png
使用異步功能
前面我們只實現(xiàn)了一個單純的提示框功能,它會自動隱藏掉知允。在多數(shù)項目中搭独,還會涉及到異步操作的等待提示,比如網(wǎng)絡(luò)下載數(shù)據(jù)廊镜,那就要在提示的時候牙肝,后臺下載數(shù)據(jù),完成后再自動隱藏掉。
func asyncShow(){
var hud = MBProgressHUD.showHUDAddedTo(self.view, animated: true)
hud.labelText = "請稍等配椭,數(shù)據(jù)加載中,預(yù)計10秒中"
hud.showAnimated(true, whileExecutingBlock: {
//異步任務(wù)虫溜,在后臺運行的任務(wù)
sleep(10)
}) {
//執(zhí)行完成后的操作,移除
hud.removeFromSuperview()
hud = nil
}
}