MBProgressHUD 是一个用来做没有文档的 UIProgressHUD UIKit 类的替代品。其就是用来显示一个正在下载中的指示器。这个东西很容易使用,并且有很好的文档,你需要几分钟就可以把其集成到你的应用中。你可以到 github repository上查看其资料。作者号称其99%的应用都使用了这个东西。
1. 网上下载 MBProgessHUD 类,导入到工程。下载地址:https://github.com/jdg/MBProgressHUD
2. 导入头文件,#import "MBProgressHUD.h" ,并在类中实现 MBProgressHUDDelegate 代理。
3. 在类里面定义:MBProgressHUD* progress_;
4. 代码实现过程。
显示:
[plain]view plaincopy
progress_ = [[MBProgressHUD alloc] initWithView:self.tableView];
[self.view addSubview:progress_];
[self.view bringSubviewToFront:progress_];
progress_.delegate = self;
progress_.labelText = @"加载中...";
[progress_ show:YES];
隐藏:
[plain]view plaincopy
if (progress_)
{
[progress_ removeFromSuperview];
[progress_ release];
progress_ = nil;
}
5. 实现协议:
[plain]view plaincopy
- (void)hudWasHidden:(MBProgressHUD *)hud
{
NSLog(@"Hud: %@", hud);
// Remove HUD from screen when the HUD was hidded
[progress_ removeFromSuperview];
[progress_ release];
progress_ = nil;
}
网友评论