!需自行安装MBProgressHUD
#import "MBProgressHUD.h"
@property (nonatomic, strong) MBProgressHUD* myHud;
/**
* 提示正在加载中,带进度动画,必须调用关闭方法hideLoading
*/
- (void)showLoading
{
//如果提示器未隐藏, 则先隐藏提示器
if (![self.myHud isHidden]) {
[self.myHud hideAnimated:YES];
self.myHud = nil;
}
//显示提示器
self.myHud = [MBProgressHUD showHUDAddedTo:[UIApplication sharedApplication].delegate.window animated:YES];
self.myHud.mode = MBProgressHUDModeIndeterminate;
self.myHud.label.textColor = [UIColor whiteColor];
self.myHud.bezelView.color = [UIColor blackColor];
//提示器字体和菊花颜色
self.myHud.contentColor =[UIColor whiteColor];
// [self.myHud setActivityIndicatorColor:[UIColor whiteColor]];
self.myHud.label.text = @"正在加载...";
}
/**
* 提示正在加载中,带进度动画,必须调用关闭方法hideLoading
*/
- (void)showLoadingMsg:(NSString*)msg
{
//如果提示器未隐藏, 则先隐藏提示器
if (![self.myHud isHidden]) {
[self.myHud hideAnimated:YES];
self.myHud = nil;
}
//显示提示器
self.myHud = [MBProgressHUD showHUDAddedTo:[UIApplication sharedApplication].delegate.window animated:YES];
self.myHud.mode = MBProgressHUDModeIndeterminate;
self.myHud.label.textColor = [UIColor whiteColor];
self.myHud.bezelView.color = [UIColor blackColor];
//提示器字体和菊花颜色
self.myHud.contentColor =[UIColor whiteColor];
// [self.myHud setActivityIndicatorColor:[UIColor whiteColor]];
self.myHud.label.text = msg;
}
/**
* 关闭正在加载中进度动画
*/
- (void)hideLoading
{
//如果提示器未隐藏, 则先隐藏提示器
if (![self.myHud isHidden]) {
[self.myHud hideAnimated:YES];
self.myHud = nil;
}
}
/**
* 纯文本方式显示提示文字, 显示3秒后自动消失
*
* @param alertMsg 提示内容
*/
- (void)showAlert:(NSString*)alertMsg
{
//如果提示器未隐藏, 则先隐藏提示器
if (![self.myHud isHidden]) {
[self.myHud hideAnimated:YES];
self.myHud = nil;
}
//显示提示器
self.myHud = [MBProgressHUD showHUDAddedTo:[UIApplication sharedApplication].delegate.window animated:YES];
//显示纯文本方式
self.myHud.mode = MBProgressHUDModeText;
self.myHud.bezelView.color = [UIColor blackColor];
self.myHud.label.text = alertMsg;
self.myHud.label.textColor = [UIColor whiteColor];
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, 2.5 * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void) {
// Do something...
[self.myHud hideAnimated:YES];
});
}
//自定义提示框消失时间
- (void)showMessage:(NSString *)alertMsg WithTime:(int)time
{
//如果提示器未隐藏, 则先隐藏提示器
if (![self.myHud isHidden]) {
[self.myHud hideAnimated:YES];
self.myHud = nil;
}
//显示提示器
self.myHud = [MBProgressHUD showHUDAddedTo:[UIApplication sharedApplication].delegate.window animated:YES];
//显示纯文本方式
self.myHud.mode = MBProgressHUDModeText;
self.myHud.bezelView.color = [UIColor blackColor];
self.myHud.label.text = alertMsg;
self.myHud.label.textColor = [UIColor whiteColor];
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, time * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void) {
// Do something...
[self.myHud hideAnimated:YES];
});
}
/**
* 显示成功提示, 有对勾图片
*
* @param sucMsg 提示文字
*/
- (void)showSuc:(NSString*)sucMsg
{
//如果提示器未隐藏, 则先隐藏提示器
if (![self.myHud isHidden]) {
[self.myHud hideAnimated:YES];
self.myHud = nil;
}
//显示提示器
self.myHud = [MBProgressHUD showHUDAddedTo:[UIApplication sharedApplication].delegate.window animated:YES];
//显示自定义图片加文本方式显示
self.myHud.label.text = sucMsg;
self.myHud.bezelView.color = [UIColor blackColor];
self.myHud.label.textColor = [UIColor whiteColor];
self.myHud.mode = MBProgressHUDModeCustomView;
//可以设置对应的图片;
self.myHud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"success"]];
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, 2.5 * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void) {
// Do something...
[self.myHud hideAnimated:YES];
});
}
/**
* 显示失败提示
*
* @param failMsg 提示文字
*/
- (void)showFail:(NSString*)failMsg
{
//如果提示器未隐藏, 则先隐藏提示器
if (![self.myHud isHidden]) {
[self.myHud hideAnimated:YES];
self.myHud = nil;
}
//显示提示器
self.myHud = [MBProgressHUD showHUDAddedTo:[UIApplication sharedApplication].delegate.window animated:YES];
//显示自定义图片加文本方式显示
self.myHud.label.text = failMsg;
self.myHud.label.textColor = [UIColor whiteColor];
self.myHud.bezelView.color = [UIColor blackColor];
self.myHud.mode = MBProgressHUDModeCustomView;
//可以设置对应的图片;
self.myHud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"error"]];
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, 2.5 * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void) {
[self.myHud hideAnimated:YES];
});
}