MBProgressHUD

IOS

https://github.com/jdg/MBProgressHUD

MBProgressHUD 是目前Github上star最多的HUD,支持所有版本的iOS,但是不支持Mac。

效果图

安装

Cocoapods

在Podfile里面添加

pod 'MBProgressHUD', '~> 0.9.2'

或者:

Carthage

在Cartfile里面添加

github "jdg/MBProgressHUD" ~> 0.9.2

或者:

Source files

直接把 MBProgressHUD.h和MBProgressHUD.m添加到工程中。

或者:

Static library

把MBProgressHUD.xcodeproj拖到工程文件中,Libraries中添加libMBProgressHUD.a,再将MBProgressHUD添加到Target Dependencies list里面。

使用

标准情况

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 {
	// Do something usefull in here instead of sleeping ...
	sleep(3);
}	
	

带进度条的情况

HUD = [[MBProgressHUD alloc] initWithView:self.navigationController.view];
	[self.navigationController.view addSubview:HUD];
	
	// Set determinate mode
	HUD.mode = MBProgressHUDModeAnnularDeterminate;
	
	HUD.delegate = self;
	HUD.labelText = @"Loading";
	
	// myProgressTask uses the HUD instance to update progress
	[HUD showWhileExecuting:@selector(myProgressTask) onTarget:self withObject:nil animated:YES];
	

- (void)myProgressTask {
	// This just increases the progress indicator in a loop
	float progress = 0.0f;
	while (progress < 1.0f) {
		progress += 0.01f;
		HUD.progress = progress;
		usleep(50000);
	}
}

更详细的用法可以参考官方的DEMO