https://github.com/jdg/MBProgressHUD
MBProgressHUD 是目前Github上star最多的HUD,支持所有版本的iOS,但是不支持Mac。
效果图
安装
Cocoapods
在Podfile
里面添加
1
| pod 'MBProgressHUD', '~> 0.9.2'
|
或者:
Carthage
在Cartfile
里面添加
1
| github "jdg/MBProgressHUD" ~> 0.9.2
|
或者:
Source files
直接把 MBProgressHUD.h
和MBProgressHUD.m
添加到工程中。
或者:
Static library
把MBProgressHUD.xcodeproj
拖到工程文件中,Libraries中添加libMBProgressHUD.a
,再将MBProgressHUD
添加到Target Dependencies list
里面。
使用
标准情况
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| HUD = [[MBProgressHUD alloc] initWithView:self.navigationController.view]; [self.navigationController.view addSubview:HUD]; HUD.delegate = self; HUD.labelText = @"Loading"; HUD.detailsLabelText = @"updating data"; HUD.square = YES; [HUD showWhileExecuting:@selector(myTask) onTarget:self withObject:nil animated:YES];
- (void)myTask { sleep(3); }
|
带进度条的情况
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| HUD = [[MBProgressHUD alloc] initWithView:self.navigationController.view]; [self.navigationController.view addSubview:HUD]; HUD.mode = MBProgressHUDModeAnnularDeterminate; HUD.delegate = self; HUD.labelText = @"Loading"; [HUD showWhileExecuting:@selector(myProgressTask) onTarget:self withObject:nil animated:YES];
- (void)myProgressTask { float progress = 0.0f; while (progress < 1.0f) { progress += 0.01f; HUD.progress = progress; usleep(50000); } }
|
更详细的用法可以参考官方的DEMO