麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 學院 > 開發設計 > 正文

MBProgressHUD第三方庫使用

2019-11-14 18:43:17
字體:
來源:轉載
供稿:網友

關鍵操作:

 

效果如下:

 

ViewController.h

1 #import <UIKit/UIKit.h>2 #import "MBPRogressHUD.h"3 4 @interface ViewController : UITableViewController<MBProgressHUDDelegate>5 @property (strong, nonatomic) MBProgressHUD *hud;6 @property (copy, nonatomic) NSArray *arrMode;7 @property (copy, nonatomic) NSArray *arrModeName;8 9 @end

ViewController.m

  1 #import "ViewController.h"  2   3 @interface ViewController ()  4 - (void)loadData;  5 - (void)layoutUI;  6 - (void)taskOfIndeterminate;  7 - (void)taskOfDeterminate;  8 - (void)taskOfDeterminateHorizontalBar;  9 - (void)taskOfAnnularDeterminate; 10 - (void)taskOfCustomView; 11 - (void)taskOfText; 12 - (void)showHUDByIndeterminate; 13 - (void)showHUDByDeterminate; 14 - (void)showHUDByDeterminateHorizontalBar; 15 - (void)showHUDByAnnularDeterminate; 16 - (void)showHUDByCustomView; 17 - (void)showHUDByText; 18 @end 19  20 @implementation ViewController 21  22 - (void)viewDidLoad { 23     [super viewDidLoad]; 24      25     [self loadData]; 26     [self layoutUI]; 27 } 28  29 - (void)didReceiveMemoryWarning { 30     [super didReceiveMemoryWarning]; 31     // Dispose of any resources that can be recreated. 32 } 33  34 - (void)loadData { 35     _arrMode = @[ @"MBProgressHUDModeIndeterminate", 36                   @"MBProgressHUDModeDeterminate", 37                   @"MBProgressHUDModeDeterminateHorizontalBar", 38                   @"MBProgressHUDModeAnnularDeterminate", 39                   @"MBProgressHUDModeCustomView", 40                   @"MBProgressHUDModeText" ]; 41      42     _arrModeName = @[ @"UIActivityIndicatorView 來顯示進度,這是默認值", 43                       @"圓形餅圖來顯示進度", 44                       @"水平進度條來顯示進度", 45                       @"圓環來顯示進度", 46                       @"自定義視圖;例如通過這種方式,來顯示一個正確或錯誤的提示圖", 47                       @"只顯示文本" ]; 48 } 49  50 - (void)layoutUI { 51     self.navigationItem.title = @"MBProgressHUD 第三方庫使用"; 52 } 53  54 #pragma mark - MBProgressHUD Additional Task 55 - (void)taskOfIndeterminate { 56     sleep(3); //進程掛起3秒,這里僅僅是模擬,相當于執行了一些操作耗時3秒;sleep 和 usleep 都是進程掛起操作方法,他們的精準度不同,所以按需使用;對于一般秒級別操作,就使用 sleep 方法 57 } 58  59 - (void)taskOfDeterminate { 60     CGFloat progressVal = 0.0f; 61     while (progressVal < 1.0) { 62         progressVal += 0.1; 63         _hud.progress = progressVal; 64         usleep(500000); //千分之一毫秒,即百萬分之一秒;這里設置進程掛起0.5秒 65     } 66 } 67  68 - (void)taskOfDeterminateHorizontalBar { 69     [self taskOfDeterminate]; 70 } 71  72 - (void)taskOfAnnularDeterminate { 73     [self taskOfDeterminate]; 74 } 75  76 - (void)taskOfCustomView { 77     [self taskOfIndeterminate]; 78 } 79  80 - (void)taskOfText { 81     [self taskOfIndeterminate]; 82 } 83  84 #pragma mark - MBProgressHUD 85 - (void)showHUDByIndeterminate { 86     UIColor *color = [UIColor cyanColor]; 87      88     _hud = [[MBProgressHUD alloc] initWithView:self.view]; 89     _hud.activityIndicatorColor = color; //設置指示器顏色;默認為白色 90      91     //label 和 detailsLabel 是公共部分,其他模式的展示效果一樣可以用 92     _hud.labelText = @"加載中..."; 93     _hud.labelFont = [UIFont systemFontOfSize:17]; 94     _hud.labelColor = color; //設置文本顏色;默認為白色 95     _hud.detailsLabelText = @"用戶請稍候,耐心等待"; 96     _hud.detailsLabelFont = [UIFont systemFontOfSize:14]; 97     _hud.detailsLabelColor = color; //設置詳細文本顏色;默認為白色 98      99     //一些額外不常用的設置100     _hud.minShowTime = 5.0f;101     _hud.opacity = 0.5f;102     _hud.animationType = MBProgressHUDAnimationZoomOut;103     _hud.cornerRadius = 15.0f;104     _hud.dimBackground = YES;105     _hud.xOffset = 0.0f;106     _hud.yOffset = 50.0f;107     _hud.margin = 30.0f;108     _hud.square = YES;109     _hud.minSize = CGSizeMake(240.0f, 200.0f); //設置了 minSize 后,square 就失效了110     111     //設置委托,以便調用hudWasHidden:方法112     _hud.delegate = self;113     [self.view addSubview:_hud];114     115     //操作方式一:116     //    [_hud showWhileExecuting:@selector(taskOfIndeterminate)117     //                    onTarget:self118     //                  withObject:nil119     //                    animated:YES];120     121     //操作方式二:122     [_hud showAnimated:YES123    whileExecutingBlock:^{124        [self taskOfIndeterminate];125    } completionBlock:^{126        NSLog(@"showHUDByIndeterminate 執行完成");127    }];128 }129 130 - (void)showHUDByDeterminate {131     _hud = [[MBProgressHUD alloc] initWithView:self.view];132     _hud.mode = MBProgressHUDModeDeterminate;133     [self.view addSubview:_hud];134     135     [_hud showAnimated:YES136    whileExecutingBlock:^{137        [self taskOfDeterminate];138    } completionBlock:^{139        NSLog(@"showHUDByDeterminate 執行完成");140    }];141 }142 143 - (void)showHUDByDeterminateHorizontalBar {144     _hud = [[MBProgressHUD alloc] initWithView:self.view];145     _hud.mode = MBProgressHUDModeDeterminateHorizontalBar;146     [self.view addSubview:_hud];147     148     [_hud showAnimated:YES149    whileExecutingBlock:^{150        [self taskOfDeterminateHorizontalBar];151    } completionBlock:^{152        NSLog(@"showHUDByDeterminateHorizontalBar 執行完成");153    }];154 }155 156 - (void)showHUDByAnnularDeterminate {157     _hud = [[MBProgressHUD alloc] initWithView:self.view];158     _hud.mode = MBProgressHUDModeAnnularDeterminate;159     [self.view addSubview:_hud];160     161     [_hud showAnimated:YES162    whileExecutingBlock:^{163        [self taskOfAnnularDeterminate];164    } completionBlock:^{165        NSLog(@"showHUDByAnnularDeterminate 執行完成");166    }];167 }168 169 - (void)showHUDByCustomView {170     _hud = [[MBProgressHUD alloc] initWithView:self.view];171     _hud.mode = MBProgressHUDModeCustomView;172     _hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"AlbumCellRedSelected"]];173     [self.view addSubview:_hud];174     175     [_hud showAnimated:YES176    whileExecutingBlock:^{177        [self taskOfCustomView];178    } completionBlock:^{179        NSLog(@"showHUDByCustomView 執行完成");180    }];181 182 }183 184 - (void)showHUDByText {185     UIColor *color = [UIColor cyanColor];186     187     _hud = [[MBProgressHUD alloc] initWithView:self.view];188     _hud.mode = MBProgressHUDModeText;189     _hud.labelText = @"加載中...";190     _hud.labelFont = [UIFont systemFontOfSize:17];191     _hud.labelColor = color; //設置文本顏色;默認為白色192     _hud.detailsLabelText = @"用戶請稍候,耐心等待";193     _hud.detailsLabelFont = [UIFont systemFontOfSize:14];194     _hud.detailsLabelColor = color; //設置詳細文本顏色;默認為白色195     [self.view addSubview:_hud];196 197     [_hud showAnimated:YES198    whileExecutingBlock:^{199        [self taskOfText];200    } completionBlock:^{201        NSLog(@"showHUDByText 執行完成");202    }];203 }204 205 #pragma mark - MBProgressHUDDelegate206 - (void)hudWasHidden:(MBProgressHUD *)hud {207     NSLog(@"隱藏后做一些操作");208 }209 210 #pragma mark - TableView211 - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {212     return @"展示模式列表";213 }214 215 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {216     return 1;217 }218 219 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {220     return _arrMode.count;221 }222 223 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {224     static NSString *cellIdentifier = @"cellIdentifier";225     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];226     if (!cell) {227         cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];228     }229     230     NSInteger row = indexPath.row;231     cell.textLabel.text = _arrMode[row];232     cell.textLabel.adjustsFontSizeToFitWidth = YES;233     cell.detailTextLabel.text = _arrModeName[row];234     cell.detailTextLabel.adjustsFontSizeToFitWidth = YES;235     236     return cell;237 }238 239 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {240     switch (indexPath.row) {241         case 0:242             [self showHUDByIndeterminate];243             break;244         case 1:245             [self showHUDByDeterminate];246             break;247         case 2:248             [self showHUDByDeterminateHorizontalBar];249             break;250         case 3:251             [self showHUDByAnnularDeterminate];252             break;253         case 4:254             [self showHUDByCustomView];255             break;256         case 5:257             [self showHUDByText];258             break;259     }260     261     NSLog(@"%ld", (long)indexPath.row);262 }263 264 @end

AppDelegate.h

1 #import <UIKit/UIKit.h>2 3 @interface AppDelegate : UIResponder <UIapplicationDelegate>4 5 @property (strong, nonatomic) UIWindow *window;6 @property (strong, nonatomic) UINavigationController *navigationController;7 8 @end

AppDelegate.m

 1 #import "AppDelegate.h" 2 #import "ViewController.h" 3  4 @interface AppDelegate () 5  6 @end 7  8 @implementation AppDelegate 9 10 11 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {12     _window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];13     ViewController *viewController = [[ViewController alloc] init];14     _navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];15     _window.rootViewController = _navigationController;16     //[_window addSubview:_navigationController.view]; //當_window.rootViewController關聯時,這一句可有可無17     [_window makeKeyAndVisible];18     return YES;19 }20 21 - (void)applicationWillResignActive:(UIApplication *)application {22 }23 24 - (void)applicationDidEnterBackground:(UIApplication *)application {25 }26 27 - (void)applicationWillEnterForeground:(UIApplication *)application {28 }29 30 - (void)applicationDidBecomeActive:(UIApplication *)application {31 }32 33 - (void)applicationWillTerminate:(UIApplication *)application {34 }35 36 @end

輸出結果:

 1 2015-07-11 13:48:30.788 MBProgressHUDDemo[7211:111189] 0 2 2015-07-11 13:48:36.090 MBProgressHUDDemo[7211:111189] showHUDByIndeterminate 執行完成 3 2015-07-11 13:48:36.091 MBProgressHUDDemo[7211:111189] 隱藏后做一些操作 4 2015-07-11 13:48:37.378 MBProgressHUDDemo[7211:111189] 1 5 2015-07-11 13:48:43.208 MBProgressHUDDemo[7211:111189] showHUDByDeterminate 執行完成 6 2015-07-11 13:48:44.435 MBProgressHUDDemo[7211:111189] 2 7 2015-07-11 13:48:50.278 MBProgressHUDDemo[7211:111189] showHUDByDeterminateHorizontalBar 執行完成 8 2015-07-11 13:48:51.692 MBProgressHUDDemo[7211:111189] 3 9 2015-07-11 13:48:57.529 MBProgressHUDDemo[7211:111189] showHUDByAnnularDeterminate 執行完成10 2015-07-11 13:48:58.473 MBProgressHUDDemo[7211:111189] 411 2015-07-11 13:49:01.778 MBProgressHUDDemo[7211:111189] showHUDByCustomView 執行完成12 2015-07-11 13:49:02.790 MBProgressHUDDemo[7211:111189] 513 2015-07-11 13:49:06.096 MBProgressHUDDemo[7211:111189] showHUDByText 執行完成

 


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 久久国产秒 | 国产91大片 | 污片在线观看视频 | 一级做人爱c黑人影片 | 日韩在线欧美在线 | 天天干干 | 毛片视频播放 | 中文字幕在线资源 | 欧美视频一二三区 | 亚洲电影在线播放 | 亚洲精品一区二区三区在线看 | 国产亚洲精彩视频 | 久久sp| 欧美91看片特黄aaaa | 国产午夜三级一区二区三桃花影视 | 精品国产视频一区二区三区 | 成人福利网| 欧美性受xxx黑人xyx性爽 | 越南一级黄色片 | 第一区免费在线观看 | 污污黄| 羞羞网站在线看 | 成人国产精品色哟哟 | 成人在线免费观看小视频 | 久久毛片 | 色天使中文字幕 | 欧美亚洲国产一区二区三区 | 免费看搡女人无遮挡的视频 | 成熟女人特级毛片www免费 | 91色一区二区三区 | 国产精品视频1区 | 性aaa | 欧美亚洲国产成人 | 国产精品免费观在线 | 欧产日产国产精品v | 国产欧美精品一区二区三区四区 | a网在线 | 久久久久久久免费看 | 亚洲成人精品一区二区 | 91小视频在线观看免费版高清 | 国产在线观看91精品 |