日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

iOS MBProgressHUD 之带底板的加载提示

發布時間:2023/12/10 编程问答 43 豆豆
生活随笔 收集整理的這篇文章主要介紹了 iOS MBProgressHUD 之带底板的加载提示 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

文章來自:http://blog.csdn.net/ryantang03/article/details/7877120

MBProgressHUD是一個開源項目,實現了很多種樣式的提示框,使用上簡單、方便,并且可以對顯示的內容進行自定義,功能很強大,很多項目中都有使用到。到GitHub上可以下載到項目源碼https://github.com/jdg/MBProgressHUD,下載下來后直接把MBProgressHUD.h和MBProgressHUD.m拖入工程中就行,別忘了選擇拷貝到工程。完了在需要使用的地方導入頭文件就可以開始使用了。首先看下工程截圖:

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??

?

接下來是整個Demo的完整界面,這里我只選擇出了幾個常用的對話框,其他樣式的在源碼提供的Demo里可以找到,要用的話直接參考就可以。

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??

接下來直接上代碼了,頭文件部分:

?

[cpp] view plaincopy
  • #import?<UIKit/UIKit.h>??
  • #import?"MBProgressHUD.h"??
  • ??
  • @interface?ViewController?:?UIViewController??
  • {??
  • ????//HUD(Head-Up?Display,意思是抬頭顯示的意思)??
  • ????MBProgressHUD?*HUD;??
  • }??
  • ??
  • -?(IBAction)showTextDialog:(id)sender;??
  • -?(IBAction)showProgressDialog:(id)sender;??
  • -?(IBAction)showProgressDialog2:(id)sender;??
  • -?(IBAction)showCustomDialog:(id)sender;??
  • -?(IBAction)showAllTextDialog:(id)sender;??
  • ??
  • @end??

  • 實現文件(按鈕實現部分):

    ?

    [cpp] view plaincopy
  • -?(IBAction)showTextDialog:(id)sender?{??
  • ????//初始化進度框,置于當前的View當中??
  • ????HUD?=?[[MBProgressHUD?alloc]?initWithView:self.view];??
  • ????[self.view?addSubview:HUD];??
  • ??????
  • ????//如果設置此屬性則當前的view置于后臺??
  • ????HUD.dimBackground?=?YES;??
  • ??????
  • ????//設置對話框文字??
  • ????HUD.labelText?=?@"請稍等";??
  • ??????
  • ????//顯示對話框??
  • ????[HUD?showAnimated:YES?whileExecutingBlock:^{??
  • ????????//對話框顯示時需要執行的操作??
  • ????????sleep(3);??
  • ????}?completionBlock:^{??
  • ????????//操作執行完后取消對話框??
  • ????????[HUD?removeFromSuperview];??
  • ????????[HUD?release];??
  • ????????HUD?=?nil;??
  • ????}];??
  • }??
  • ??
  • -?(IBAction)showProgressDialog:(id)sender?{??
  • ????HUD?=?[[MBProgressHUD?alloc]?initWithView:self.view];??
  • ????[self.view?addSubview:HUD];??
  • ????HUD.labelText?=?@"正在加載";??
  • ??????
  • ????//設置模式為進度框形的??
  • ????HUD.mode?=?MBProgressHUDModeDeterminate;??
  • ????[HUD?showAnimated:YES?whileExecutingBlock:^{??
  • ????????float?progress?=?0.0f;??
  • ????????while?(progress?<?1.0f)?{??
  • ????????????progress?+=?0.01f;??
  • ????????????HUD.progress?=?progress;??
  • ????????????usleep(50000);??
  • ????????}??
  • ????}?completionBlock:^{??
  • ????????[HUD?removeFromSuperview];??
  • ????????[HUD?release];??
  • ????????HUD?=?nil;??
  • ????}];??
  • }??
  • ??
  • -?(IBAction)showProgressDialog2:(id)sender?{??
  • ????HUD?=?[[MBProgressHUD?alloc]?initWithView:self.view];??
  • ????[self.view?addSubview:HUD];??
  • ????HUD.labelText?=?@"正在加載";??
  • ????HUD.mode?=?MBProgressHUDModeAnnularDeterminate;??
  • ??????
  • ????[HUD?showAnimated:YES?whileExecutingBlock:^{??
  • ????????float?progress?=?0.0f;??
  • ????????while?(progress?<?1.0f)?{??
  • ????????????progress?+=?0.01f;??
  • ????????????HUD.progress?=?progress;??
  • ????????????usleep(50000);??
  • ????????}??
  • ????}?completionBlock:^{??
  • ????????[HUD?removeFromSuperview];??
  • ????????[HUD?release];??
  • ????????HUD?=?nil;??
  • ????}];??
  • }??
  • ??
  • -?(IBAction)showCustomDialog:(id)sender?{??
  • ????HUD?=?[[MBProgressHUD?alloc]?initWithView:self.view];??
  • ????[self.view?addSubview:HUD];??
  • ????HUD.labelText?=?@"操作成功";??
  • ????HUD.mode?=?MBProgressHUDModeCustomView;??
  • ????HUD.customView?=?[[[UIImageView?alloc]?initWithImage:[UIImage?imageNamed:@"Checkmark"]]?autorelease];??
  • ????[HUD?showAnimated:YES?whileExecutingBlock:^{??
  • ????????sleep(2);??
  • ????}?completionBlock:^{??
  • ????????[HUD?removeFromSuperview];??
  • ????????[HUD?release];??
  • ????????HUD?=?nil;??
  • ????}];??
  • ??????
  • }??
  • ??
  • -?(IBAction)showAllTextDialog:(id)sender?{??
  • ????HUD?=?[[MBProgressHUD?alloc]?initWithView:self.view];??
  • ????[self.view?addSubview:HUD];??
  • ????HUD.labelText?=?@"操作成功";??
  • ????HUD.mode?=?MBProgressHUDModeText;??
  • ??????
  • ????//指定距離中心點的X軸和Y軸的偏移量,如果不指定則在屏幕中間顯示??
  • //????HUD.yOffset?=?150.0f;??
  • //????HUD.xOffset?=?100.0f;??
  • ??????
  • ????[HUD?showAnimated:YES?whileExecutingBlock:^{??
  • ????????sleep(2);??
  • ????}?completionBlock:^{??
  • ????????[HUD?removeFromSuperview];??
  • ????????[HUD?release];??
  • ????????HUD?=?nil;??
  • ????}];??
  • }??

  • 依次實現的效果如下:

    ? ? ? ? ? ?? ? ? ? ? ? ? ?


    ? ? ? ? ? ?? ? ? ? ? ? ? ?

    下面這個效果就類似Android中的Toast:

    ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ???

    以上就簡單介紹了MBProgressHUD的使用,這里都是采用block的形式來操作的,這樣寫起代碼來更直觀也更高效。

    轉載于:https://www.cnblogs.com/wangyang1213/p/5300844.html

    總結

    以上是生活随笔為你收集整理的iOS MBProgressHUD 之带底板的加载提示的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。