iOS MBProgressHUD的基本使用

2021-09-22 09:37:12 字數 3679 閱讀 1999

//

方式1.直接在view上show

hud =[[mbprogresshud showhudaddedto:self.view animated:yes] retain];

hud.

delegate =self;

//常用的設定

//小矩形的背景色

hud.color = [uicolor clearcolor];//

這兒表示無背景

//顯示的文字

hud.labeltext = @"

test

";

//細節文字

hud.detailslabeltext = @"

test detail

";

//是否有庶罩

hud.dimbackground =yes;

[hud hide:yes afterdelay:

2];

//只顯示文字

mbprogresshud *hud =[mbprogresshud showhudaddedto:self.view animated:yes];

hud.mode =mbprogresshudmodetext;

hud.labeltext = @"

some message...

";

hud.margin = 10

.f;

hud.yoffset = 150

.f;

hud.removefromsuperviewonhide =yes;

[hud hide:yes afterdelay:

3];

//方式2.initwithview

//use block

hud =[[mbprogresshud alloc] initwithview:self.view];

[self.view addsubview:hud];

hud.labeltext = @"

test

";

[hud showanimated:yes whileexecutingblock:^ completionblock:^];

//圓形進度條

hud =[[mbprogresshud alloc] initwithview:self.view];

[self.view addsubview:hud];

hud.mode =mbprogresshudmodeannulardeterminate;

hud.

delegate =self;

hud.labeltext = @"

loading

";

[hud showwhileexecuting:@selector(myprogresstask) ontarget:self withobject:nil animated:yes];

//自定義view

hud =[[mbprogresshud alloc] initwithview:self.view];

hud.customview = [[[uiimageview alloc] initwithimage:[uiimage imagenamed:@"

37x-checkmark.png

"]] autorelease];

//set custom view mode

hud.mode =mbprogresshudmodecustomview;

hud.

delegate =self;

hud.labeltext = @"

completed

";

[hud show:yes];

[hud hide:yes afterdelay:

3];

**方法:

#pragma mark -  

#pragma mark hud的**方法,關閉hud時執行

-(void)hudwashidden:(mbprogresshud *)hud

二個task

-(void

) dotask

-(void

) myprogresstask

}

注意: 其實,第三方庫都是開源的,我們可以在其基礎上新增另外自己需要的功能,如果覺得上面顯示文字**太不好用,可以新增乙個分類,對它設定文字的方法再次封裝如下所示:

新增乙個分類:mbprogresshud+xyq

mbprogresshud+xyq.**件:

#import

"mbprogresshud

"@inte***ce

mbprogresshud (xyq)

+ (void)showsuccess:(nsstring *)success toview:(uiview *)view;

+ (void)showerror:(nsstring *)error toview:(uiview *)view;

+ (mbprogresshud *)showmessage:(nsstring *)message toview:(uiview *)view;

+ (void)showsuccess:(nsstring *)success;

+ (void)showerror:(nsstring *)error;

+ (mbprogresshud *)showmessage:(nsstring *)message;

+ (void)hidehudforview:(uiview *)view;

+ (void

)hidehud;

@end

mbprogresshud+xyq.m檔案:

#import

"mbprogresshud+xyq.h

"@implementation

mbprogresshud (xyq)

#pragma mark 顯示資訊

+ (void)show:(nsstring *)text icon:(nsstring *)icon view:(uiview *)view

#pragma mark 顯示錯誤資訊

+ (void)showerror:(nsstring *)error toview:(uiview *)view

+ (void)showsuccess:(nsstring *)success toview:(uiview *)view

#pragma mark 顯示一些資訊

+ (mbprogresshud *)showmessage:(nsstring *)message toview:(uiview *)view

+ (void)showsuccess:(nsstring *)success

+ (void)showerror:(nsstring *)error

+ (mbprogresshud *)showmessage:(nsstring *)message

+ (void)hidehudforview:(uiview *)view

+ (void

)hidehud

@end

程式猿神奇的手,每時每刻,這雙手都在改變著世界的互動方式!

IOS MBProgressHUD常見的幾種用法

用法一 最簡單的用法,不需要其他的操作 1 在資料載入之前新增 mbprogresshud showhudaddedto self view animated yes 開始載入資料提示 2 在資料載入成功之後新增 mbprogresshud hidehudforview self view anim...

iOS MBProgressHUD的使用方法

mbprogresshud就是乙個非常好用的第三方庫,可以快速接入載入的介面,下面貼 下面的 包含了各種常用型別的載入 import viewcontroller.h import mbprogresshud.h inte ce viewcontroller property atomic,assi...

scanf gets getchar的基本使用

scanf 是在c語言中最常用的輸入函式,它需要我們嚴格按照要求進行輸入,除非你用對scanf 使用了正規表示式 對於scanf 當它遇到空格 回車 或者tab鍵時,都會自動停止輸入,剩下的內容逗留在緩衝區中,所以如果需要輸入字串,不推薦使用它。關於正規表示式 是個集合的標誌,特指讀入此集合所限定的...