国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

MBProgressHUD第三方庫使用

2019-11-14 18:43:17
字體:
供稿:網(wǎng)友

關(guān)鍵操作:

 

效果如下:

 

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                       @"圓環(huán)來顯示進度", 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秒,這里僅僅是模擬,相當(dāng)于執(zhí)行了一些操作耗時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); //千分之一毫秒,即百萬分之一秒;這里設(shè)置進程掛起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; //設(shè)置指示器顏色;默認為白色 90      91     //label 和 detailsLabel 是公共部分,其他模式的展示效果一樣可以用 92     _hud.labelText = @"加載中..."; 93     _hud.labelFont = [UIFont systemFontOfSize:17]; 94     _hud.labelColor = color; //設(shè)置文本顏色;默認為白色 95     _hud.detailsLabelText = @"用戶請稍候,耐心等待"; 96     _hud.detailsLabelFont = [UIFont systemFontOfSize:14]; 97     _hud.detailsLabelColor = color; //設(shè)置詳細文本顏色;默認為白色 98      99     //一些額外不常用的設(shè)置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); //設(shè)置了 minSize 后,square 就失效了110     111     //設(shè)置委托,以便調(diào)用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 執(zhí)行完成");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 執(zhí)行完成");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 執(zhí)行完成");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 執(zhí)行完成");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 執(zhí)行完成");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; //設(shè)置文本顏色;默認為白色192     _hud.detailsLabelText = @"用戶請稍候,耐心等待";193     _hud.detailsLabelFont = [UIFont systemFontOfSize:14];194     _hud.detailsLabelColor = color; //設(shè)置詳細文本顏色;默認為白色195     [self.view addSubview:_hud];196 197     [_hud showAnimated:YES198    whileExecutingBlock:^{199        [self taskOfText];200    } completionBlock:^{201        NSLog(@"showHUDByText 執(zhí)行完成");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]; //當(dāng)_window.rootViewController關(guān)聯(lián)時,這一句可有可無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

輸出結(jié)果:

 1 2015-07-11 13:48:30.788 MBProgressHUDDemo[7211:111189] 0 2 2015-07-11 13:48:36.090 MBProgressHUDDemo[7211:111189] showHUDByIndeterminate 執(zhí)行完成 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 執(zhí)行完成 6 2015-07-11 13:48:44.435 MBProgressHUDDemo[7211:111189] 2 7 2015-07-11 13:48:50.278 MBProgressHUDDemo[7211:111189] showHUDByDeterminateHorizontalBar 執(zhí)行完成 8 2015-07-11 13:48:51.692 MBProgressHUDDemo[7211:111189] 3 9 2015-07-11 13:48:57.529 MBProgressHUDDemo[7211:111189] showHUDByAnnularDeterminate 執(zhí)行完成10 2015-07-11 13:48:58.473 MBProgressHUDDemo[7211:111189] 411 2015-07-11 13:49:01.778 MBProgressHUDDemo[7211:111189] showHUDByCustomView 執(zhí)行完成12 2015-07-11 13:49:02.790 MBProgressHUDDemo[7211:111189] 513 2015-07-11 13:49:06.096 MBProgressHUDDemo[7211:111189] showHUDByText 執(zhí)行完成

 


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 辛集市| 白朗县| 大余县| 阳信县| 博白县| 玉屏| 台北市| 武陟县| 汾西县| 恩平市| 读书| 靖宇县| 池州市| 灵璧县| 万载县| 安陆市| 南雄市| 重庆市| 苍南县| 平泉县| 堆龙德庆县| 普兰县| 灵宝市| 集贤县| 且末县| 磐安县| 临清市| 新绛县| 西林县| 灌阳县| 沙河市| 宁都县| 封丘县| 秭归县| 桐乡市| 保山市| 五常市| 西宁市| 十堰市| 黎平县| 晋中市|