使用
創(chuàng)建 MBProgressHUD的分類
.h中
#import <MBProgressHUD/MBProgressHUD.h>
@interface MBProgressHUD (PD)
+ (void)showSuccess:(NSString *)success;
+ (void)showSuccess:(NSString *)success toView:(UIView *)view;
+ (void)showError:(NSString *)error;
+ (void)showError:(NSString *)error toView:(UIView *)view;
+ (MBProgressHUD *)showMessage:(NSString *)message;
+ (MBProgressHUD *)showMessage:(NSString *)message toView:(UIView *)view;
+ (void)hideHUD;
+ (void)hideHUDForView:(UIView *)view;
@end
.m中
#import "MBProgressHUD+PD.h"
@implementation MBProgressHUD (PD)
/**
* =======顯示信息
* @param text 信息內(nèi)容
* @param icon 圖標(biāo)
* @param view 顯示的視圖
*/
+ (void)show:(NSString *)text icon:(NSString *)icon view:(UIView *)view
{
if (view == nil)
view = [[UIApplication sharedApplication].windows lastObject];
// 快速顯示一個提示信息
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
hud.label.text = text;
hud.label.textColor = Color333333;
//hud.bezelView.style = MBProgressHUDBackgroundStyleSolidCo;
hud.label.font = [UIFont systemFontOfSize:17.0];
hud.userInteractionEnabled= NO;
hud.customView = [[UIImageView alloc] initWithImage:icon]; // 設(shè)置圖片
hud.bezelView.backgroundColor = mainGrayColor; //背景顏色
// 設(shè)置圖片
hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"MBProgressHUD.bundle/%@", icon]]];
// 再設(shè)置模式
hud.mode = MBProgressHUDModeCustomView;
// 隱藏時候從父控件中移除
hud.removeFromSuperViewOnHide = YES;
// 1秒之后再消失
[hud hideAnimated:YES afterDelay:1.5];
}
/**
* =======顯示 提示信息
* @param success 信息內(nèi)容
*/
+ (void)showSuccess:(NSString *)success
{
[self showSuccess:success toView:nil];
}
/**
* =======顯示
* @param success 信息內(nèi)容
*/
+ (void)showSuccess:(NSString *)success toView:(UIView *)view
{
[self show:success icon:@"success.png" view:view];
}
/**
* =======顯示錯誤信息
*/
+ (void)showError:(NSString *)error
{
[self showError:error toView:nil];
}
+ (void)showError:(NSString *)error toView:(UIView *)view{
[self show:error icon:@"error.png" view:view];
}
/**
* 顯示提示 + 菊花
* @param message 信息內(nèi)容
* @return 直接返回一個MBProgressHUD语御, 需要手動關(guān)閉( ?
*/
+ (MBProgressHUD *)showMessage:(NSString *)message
{
return [self showMessage:message toView:nil];
}
/**
* 顯示一些信息
* @param message 信息內(nèi)容
* @param view 需要顯示信息的視圖
* @return 直接返回一個MBProgressHUD盐杂,需要手動關(guān)閉
*/
+ (MBProgressHUD *)showMessage:(NSString *)message toView:(UIView *)view {
if (view == nil) view = [[UIApplication sharedApplication].windows lastObject];
// 快速顯示一個提示信息
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
hud.label.text = message;
// 隱藏時候從父控件中移除
hud.removeFromSuperViewOnHide = YES;
// YES代表需要蒙版效果
hud.dimBackground = YES;
return hud;
}
/**
* 手動關(guān)閉MBProgressHUD
*/
+ (void)hideHUD
{
[self hideHUDForView:nil];
}
/**
* @param view 顯示MBProgressHUD的視圖
*/
+ (void)hideHUDForView:(UIView *)view
{
if (view == nil)
view = [[UIApplication sharedApplication].windows lastObject];
[self hideHUDForView:view animated:YES];
}
@end
樣式選擇
用法一:文字提示+菊花盯另,延遲s后消失饰豺,再出現(xiàn)文字提示
[MBProgressHUD showMessage:@"正在加載..."];
int64_t delayInSeconds = 2.0; // 延遲的時間
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
[MBProgressHUD hideHUD];
[MBProgressHUD showError:@"加載失敗拱层,請檢查網(wǎng)絡(luò)" toView:nil];
});
用法二:只提示文字富拗,延遲s后消失
[MBProgressHUD showError:@"登錄失敗" toView:nil];
//[MBProgressHUD showSuccess:@"成功登錄"];
輕量級SVProgressHUD
新建分類
添加分類方法
+(void)showYESmessage:(NSString *)mesg;
+(void)showNOmessage:(NSString *)mesg;
+(void)showStatesMsge:(NSString *)mesg;
+(void)showStatesMsgeWithTime:(NSString *)mesg;
實現(xiàn)
+(void)showYESmessage:(NSString *)mesg{
[SVProgressHUD showSuccessWithStatus:mesg];
[SVProgressHUD setForegroundColor:[UIColor blackColor]];
[SVProgressHUD dismissWithDelay:1]; //mesg.length/3];
}
+(void)showNOmessage:(NSString *)mesg{
//[SVProgressHUD showErrorWithStatus:mesg]; // X + 提示
[SVProgressHUD showInfoWithStatus:mesg]; // 粟矿! + 提示
[SVProgressHUD setForegroundColor:[UIColor blackColor]];
//[SVProgressHUD showImage:nil status:mesg];
[SVProgressHUD dismissWithDelay:1]; //mesg.length/3];
}
+(void)showStatesMsge:(NSString *)mesg{
[SVProgressHUD showWithStatus:mesg]; //轉(zhuǎn)圈 + 提示 ----! 需手動隱藏
[SVProgressHUD setForegroundColor:mainRedColor];
//[SVProgressHUD dismissWithDelay:1];
}
+(void)showStatesMsgeWithTime:(NSString *)mesg{
[SVProgressHUD showWithStatus:mesg];//???
[SVProgressHUD setForegroundColor:mainRedColor];
[SVProgressHUD dismissWithDelay:1.5];
}
自定義SVProgressHUD
// 設(shè)置最大磕道、小顯示時間
[SVProgressHUD setMaximumDismissTimeInterval:10.];
[SVProgressHUD setMaximumDismissTimeInterval:1.];
//設(shè)置樣式:背景黑色示弓、字體白色
[SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
//設(shè)置蒙版暗淡讳侨,不允許觸屏
[SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeBlack];
//設(shè)置蒙版顏色及透明度
[SVProgressHUD setBackgroundLayerColor:[UIColor colorWithRed:0.3 green:0.4 blue:0.5 alpha:0.2]];
// 位置 偏移
[SVProgressHUD setOffsetFromCenter:UIOffsetMake(0, SCREEN_H/3)];
// 環(huán)線圓角(默認(rèn)18pt)
[SVProgressHUD setRingRadius:20];
// 環(huán)線厚度(默認(rèn)2pt)
[SVProgressHUD setRingThickness:2];
// 設(shè)置HUD的圓角
[SVProgressHUD setCornerRadius:20];
// 設(shè)置字體
[SVProgressHUD setFont: [UIFont preferredFontForTextStyle:UIFontTextStyleCallout]];
//設(shè)置HUD前景字體、背景顏色(SVProgressHUDStyleCustom的模式下有效)
[SVProgressHUD setForegroundColor:[UIColor yellowColor]];
[SVProgressHUD setBackgroundColor:[UIColor blackColor]];
// 設(shè)置HUD的圖標(biāo)icon
[SVProgressHUD setInfoImage:[UIImage imageNamed:@"ii"]];
[SVProgressHUD showInfoWithStatus:@"密碼錯誤"];
...
[SVProgressHUD setSuccessImage:[UIImage imageNamed:@"ii"]];
[SVProgressHUD showSuccessWithStatus:@"登錄成功"];
// 設(shè)置原生動畫效果
[SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeNative];
// 設(shè)置彈出動畫
[SVProgressHUD setFadeInAnimationDuration:0.35]; //放大出現(xiàn)
[SVProgressHUD setFadeOutAnimationDuration:1.5]; // 縮小消失
相關(guān)資料
https://blog.csdn.net/wujakf/article/details/70882827
http://www.reibang.com/p/a08d4597cf24
交互式提示
UIAlertView *aler = [[UIAlertView alloc] initWithTitle:@"未檢測到支付寶!" message:@"提示信息"
delegate:self cancelButtonTitle:@"確定" otherButtonTitles: nil];
[aler show];