SVProgressHUD的一些常見用法

方法

SVProgressHUD所以的方法都是類方法,并且對象是通過單例創建。由于方法都是通過類名調用,簡單明了。

基本方法

     + (void)show;    顯示:狀態是一個迅速轉動的圈
     + (void)showWithMaskType:(SVProgressHUDMaskType)maskType; 顯示并且帶著一個狀態
     + (void)showWithStatus:(NSString*)status; 顯示并且帶著文字
     + (void)showWithStatus:(NSString*)status maskType:(SVProgressHUDMaskType)maskType;
 
     + (void)showProgress:(float)progress;  //顯示進度:狀態是一個進度圈
     + (void)showProgress:(float)progress maskType:(SVProgressHUDMaskType)maskType;
     + (void)showProgress:(float)progress status:(NSString*)status;
     + (void)showProgress:(float)progress status:(NSString*)status maskType:(SVProgressHUDMaskType)maskType;
 
     + (void)setStatus:(NSString*)string; // 改變正顯示著的HUD的文字
 
     // stops the activity indicator, shows a glyph + status, and dismisses HUD a little bit later
     + (void)showInfoWithStatus:(NSString *)string;   //顯示消息信息,其實就是中心圖片更換了
     + (void)showInfoWithStatus:(NSString *)string maskType:(SVProgressHUDMaskType)maskType;
 
     + (void)showSuccessWithStatus:(NSString*)string; //顯示成功消息
     + (void)showSuccessWithStatus:(NSString*)string maskType:(SVProgressHUDMaskType)maskType;
 
     + (void)showErrorWithStatus:(NSString *)string; //顯示錯誤消息
     + (void)showErrorWithStatus:(NSString *)string maskType:(SVProgressHUDMaskType)maskType;
 
     // use 28x28 white pngs
     + (void)showImage:(UIImage*)image status:(NSString*)status; //顯示自己設置的圖片,圖片大小事28 * 28 px
     + (void)showImage:(UIImage*)image status:(NSString*)status maskType:(SVProgressHUDMaskType)maskType;
 
     + (void)setOffsetFromCenter:(UIOffset)offset; //距離中心點的偏移量
     + (void)resetOffsetFromCenter; //返回中心點
 
     + (void)popActivity; // 消除一個HUD,根據其實現方法如果前面有執行了好幾次show方法,如果給定的progress == 0 或者 pregress < 0那樣就會讓使一個參數+1,執行這個方法會使那個參數-1,如果參數==0時 執行dismiss方法。
     + (void)dismiss; 消失
 
     + (BOOL)isVisible; 是否正在顯示

關于HUD的屬性配置

     + (void)setBackgroundColor:(UIColor*)color;       //背景顏色          // default is [UIColor whiteColor]
     + (void)setForegroundColor:(UIColor*)color;       //progress 和 label顏色          // default is [UIColor blackColor]
     + (void)setRingThickness:(CGFloat)width;          //progress 寬度          // default is 4 pt
     + (void)setFont:(UIFont*)font;                     //字體         // default is [UIFont preferredFontForTextStyle:UIFontTextStyleSubheadline]
     + (void)setInfoImage:(UIImage*)image;               //消息的圖片        // default is the bundled info image provided by Freepik
     + (void)setSuccessImage:(UIImage*)image;            //成功時的圖片        // default is the bundled success image provided by Freepik
     + (void)setErrorImage:(UIImage*)image;              //失敗時的圖片        // default is the bundled error image provided by Freepik
     + (void)setDefaultMaskType:(SVProgressHUDMaskType)maskType; //當HUD顯示時,用戶是否可以點擊其他控件// default is SVProgressHUDMaskTypeNone
 
     SVProgressHUDMaskTypeNone = 1,  // 允許用戶進行其他用戶操作
     SVProgressHUDMaskTypeClear,     // 不允許用戶進行其他用戶操作
     SVProgressHUDMaskTypeBlack,     // 不允許用戶進行其他用戶操作,并且背景是黑色的
     SVProgressHUDMaskTypeGradient   // 允許用戶進行其他用戶操作,并且背景是漸變的黑色
 
     + (void)setViewForExtension:(UIView*)view;         //可以延展一個圖片必須設置#define SV_APP_EXTENSIONS

關于HUD的通知

 extern NSString * const SVProgressHUDDidReceiveTouchEventNotification; 在HUD外點擊
 extern NSString * const SVProgressHUDDidTouchDownInsideNotification; 在HUD中點擊
 extern NSString * const SVProgressHUDWillDisappearNotification;  將要顯示
 extern NSString * const SVProgressHUDDidDisappearNotification;   已經顯示
 extern NSString * const SVProgressHUDWillAppearNotification;     將要消失
 extern NSString * const SVProgressHUDDidAppearNotification;      已經消失
 
 extern NSString * const SVProgressHUDStatusUserInfoKey; HUD的狀態

在通知中userInfo字典中存儲了HUD的狀態,其key為SVProgressHUDStatusUserInfoKey

MBProgressHUD的基本使用

    /**
     *  類方法
     */
    /*
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    @weakify(hud)
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        @strongify(hud)
        [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
    });
    */
 
    /**
     *  實例方法
     */
    MBProgressHUD *hud = [[MBProgressHUD alloc] initWithView:self.view];
 
    //顯示hud的模式
    hud.mode = MBProgressHUDModeDeterminate;
 
    //背景顏色
    hud.color = [UIColor redColor];
 
    //主標題
    hud.labelText = @"主標題";
 
    //副標題
    hud.detailsLabelText = @"副標題";
 
    //顯示、隱藏時的動畫樣式
    hud.animationType = MBProgressHUDAnimationZoomIn;
 
    //當mode的屬性是跟進度相關時,就可以設置progress的值,實現實時進度的顯示
    hud.progress = 0.8;
 
    // HUD的相對于父視圖 x 的偏移,默認居中
//    hud.xOffset = 50;
//    hud.yOffset = 50;
 
    //是否顯示蒙板
    hud.dimBackground = YES;
 
    //HUD內部視圖相對于HUD的內邊距
    hud.margin = 50;
 
    //HUD的圓角半徑
    hud.cornerRadius = 20;
 
    //最小的顯示時間
    hud.minShowTime = 3.0;
 
    // HUD的最小尺寸
    hud.minSize = CGSizeMake(300, 300);
 
    // 代理中只有一個方法,即獲得HUD隱藏后的時刻
//    hud.delegate = self;
 
    [self.view addSubview:hud];
 
    [hud showAnimated:YES whileExecutingBlock:^{
      //hud執行期間
        NSLog(@"執行期間");
    } onQueue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0) completionBlock:^{
       //hud執行完畢
        NSLog(@"執行完畢");
    }];
 
}

原文章:https://blog.csdn.net/wujakf/article/details/70882827

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容

  • 視頻處理 BeautifyFaceDemo[https://github.com/Guikunzhi/Beauti...
    香橙柚子閱讀 2,727評論 0 14
  • 久違的晴天,家長會。 家長大會開好到教室時,離放學已經沒多少時間了。班主任說已經安排了三個家長分享經驗。 放學鈴聲...
    飄雪兒5閱讀 7,575評論 16 22
  • 今天感恩節哎,感謝一直在我身邊的親朋好友。感恩相遇!感恩不離不棄。 中午開了第一次的黨會,身份的轉變要...
    迷月閃星情閱讀 10,616評論 0 11
  • 可愛進取,孤獨成精。努力飛翔,天堂翱翔。戰爭美好,孤獨進取。膽大飛翔,成就輝煌。努力進取,遙望,和諧家園。可愛游走...
    趙原野閱讀 2,778評論 1 1
  • 在妖界我有個名頭叫胡百曉,無論是何事,只要找到胡百曉即可有解決的辦法。因為是只狐貍大家以訛傳訛叫我“傾城百曉”,...
    貓九0110閱讀 3,348評論 7 3