iOS 第三方-MBProgressHUD

使用

創(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];
    // 快速顯示一個(gè)提示信息
    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;
    
    // 隱藏時(shí)候從父控件中移除
    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];
}

/**
 *  =======顯示錯(cuò)誤信息
 */
+ (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 直接返回一個(gè)MBProgressHUD, 需要手動(dòng)關(guān)閉(  ?
 */
+ (MBProgressHUD *)showMessage:(NSString *)message
{
    return [self showMessage:message toView:nil];
}

/**
 *  顯示一些信息
 *  @param message 信息內(nèi)容
 *  @param view    需要顯示信息的視圖
 *  @return 直接返回一個(gè)MBProgressHUD,需要手動(dòng)關(guān)閉
 */
+ (MBProgressHUD *)showMessage:(NSString *)message toView:(UIView *)view {
    if (view == nil) view = [[UIApplication sharedApplication].windows lastObject];
    // 快速顯示一個(gè)提示信息
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.label.text = message;
    // 隱藏時(shí)候從父控件中移除
    hud.removeFromSuperViewOnHide = YES;
    // YES代表需要蒙版效果
    hud.dimBackground = YES;
    
    return hud;
}

/**
 *  手動(dòng)關(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;      // 延遲的時(shí)間
 
 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:@"加載失敗,請(qǐng)檢查網(wǎng)絡(luò)" toView:nil];
 });
 

用法二:只提示文字,延遲s后消失

    [MBProgressHUD showError:@"登錄失敗" toView:nil];  

    //[MBProgressHUD showSuccess:@"成功登錄"];   

輕量級(jí)SVProgressHUD

新建分類
添加分類方法

+(void)showYESmessage:(NSString *)mesg;
+(void)showNOmessage:(NSString *)mesg;
+(void)showStatesMsge:(NSString *)mesg;
+(void)showStatesMsgeWithTime:(NSString *)mesg;

實(shí)現(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)圈 + 提示   ----! 需手動(dòng)隱藏
    [SVProgressHUD setForegroundColor:mainRedColor];
    
    //[SVProgressHUD dismissWithDelay:1];
}

+(void)showStatesMsgeWithTime:(NSString *)mesg{
    
    [SVProgressHUD showWithStatus:mesg];//???
    
    [SVProgressHUD setForegroundColor:mainRedColor];
    
    [SVProgressHUD dismissWithDelay:1.5];
}

自定義SVProgressHUD

// 設(shè)置最大、小顯示時(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:@"密碼錯(cuò)誤"];     
...
    [SVProgressHUD setSuccessImage:[UIImage imageNamed:@"ii"]];
    [SVProgressHUD showSuccessWithStatus:@"登錄成功"];

// 設(shè)置原生動(dòng)畫效果
    [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeNative];
// 設(shè)置彈出動(dòng)畫
    [SVProgressHUD setFadeInAnimationDuration:0.35]; //放大出現(xiàn)
    [SVProgressHUD setFadeOutAnimationDuration:1.5]; // 縮小消失


相關(guān)資料
https://blog.csdn.net/wujakf/article/details/70882827
http://www.itdecent.cn/p/a08d4597cf24

交互式提示

    UIAlertView *aler = [[UIAlertView alloc] initWithTitle:@"未檢測(cè)到支付寶!" message:@"提示信息" 
    delegate:self cancelButtonTitle:@"確定" otherButtonTitles: nil];
    [aler show];

https://www.cnblogs.com/wujy/p/5572762.html

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容