【iOS知识学习】_进度条的实现(MBProgressHUD)

在iOS的开发当中,经常会遇到读取系统资源等类似的情况,如果网络比较卡的话,用户很可能以为这个app已经挂掉了,用户体验很差,老外还是很好的,提供开源的source,跟大家一块学习下。

iOS的进度条可以分为几类,有普通的,就像一个圈圈在那转,有在圈圈下加文字的,有直接是纯文字的,等等。。

在自己的项目中需要加入以下2个文件:MBProgressHUD.h和MBProgressHUD.m;接下来我们只需要在我们的.m文件中引用progress的头文件即可。

对于普通的进度条,代码如下:

- (IBAction)showSimple:(id)sender {
	// The hud will dispable all input on the view (use the higest view possible in the view hierarchy)
	HUD = [[MBProgressHUD alloc] initWithView:self.navigationController.view];
	[self.navigationController.view addSubview:HUD];
	
	// Regiser for HUD callbacks so we can remove it from the window at the right time
	HUD.delegate = self;
	
	// Show the HUD while the provided method executes in a new thread
	[HUD showWhileExecuting:@selector(myTask) onTarget:self withObject:nil animated:YES];
}
选择器函数myTask中可以做我们想要做的事情:

- (void)myTask {
	// Do something usefull in here instead of sleeping ...
	sleep(3);
}

效果如图:


带有文字的进度条:

- (IBAction)showWithLabel:(id)sender {
	
	HUD = [[MBProgressHUD alloc] initWithView:self.navigationController.view];
	[self.navigationController.view addSubview:HUD];
	
	HUD.delegate = self;
	HUD.labelText = @"Loading";
	
	[HUD showWhileExecuting:@selector(myTask) onTarget:self withObject:nil animated:YES];
}
效果图如下:

纯文字的代码:

- (IBAction)showTextOnly:(id)sender {
	
	MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.navigationController.view animated:YES];
	
	// Configure for text only and offset down
	hud.mode = MBProgressHUDModeText;
	hud.labelText = @"Some message...";
	hud.margin = 10.f;
	hud.yOffset = 150.f;
	hud.removeFromSuperViewOnHide = YES;
	
	[hud hide:YES afterDelay:3];
}

效果图如下:

还有很多,大家可以去下载demo:http://download.csdn.net/detail/weasleyqi/4648565

参考地址:https://github.com/jdg/MBProgressHUD


  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值