hud控件的使用 SVprogressHud MBProgressHUD
-
//方式1.直接在View上show
-
HUD = [[MBProgressHUD showHUDAddedTo:self.view animated:YES] retain];
-
HUD.delegate = self;
-
-
//常用的设置
-
//小矩形的背景色
-
HUD.color = [UIColor clearColor];//这儿表示无背景
-
//显示的文字
-
HUD.labelText = @"Test";
-
//细节文字
-
HUD.detailsLabelText = @"Test detail";
-
//是否有庶罩
-
HUD.dimBackground = YES;
-
[HUD hide:YES afterDelay:2];
-
-
//只显示文字
-
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
-
hud.mode = MBProgressHUDModeText;
-
hud.labelText = @"Some message...";
-
hud.margin = 10.f;
-
hud.yOffset = 150.f;
-
hud.removeFromSuperViewOnHide = YES;
-
[hud hide:YES afterDelay:3];
-
-
//方式2.initWithView
-
//use block
-
HUD = [[MBProgressHUD alloc] initWithView:self.view];
-
[self.view addSubview:HUD];
-
HUD.labelText = @"Test";
-
[HUD showAnimated:YES whileExecutingBlock:^{
-
NSLog(@"%@",@"do somethings....");
-
[self doTask];
-
} completionBlock:^{
-
[HUD removeFromSuperview];
-
[HUD release];
-
}];
-
-
//圆形进度条
-
HUD = [[MBProgressHUD alloc] initWithView:self.view];
-
[self.view addSubview:HUD];
-
HUD.mode = MBProgressHUDModeAnnularDeterminate;
-
HUD.delegate = self;
-
HUD.labelText = @"Loading";
-
[HUD showWhileExecuting:@selector(myProgressTask) onTarget:self withObject:nil animated:YES];
-
-
//自定义view
-
HUD = [[MBProgressHUD alloc] initWithView:self.view];
-
HUD.customView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"37x-Checkmark.png"]] autorelease];
-
// Set custom view mode
-
HUD.mode = MBProgressHUDModeCustomView;
-
HUD.delegate = self;
-
HUD.labelText = @"Completed";
-
[HUD show:YES];
-
[HUD hide:YES afterDelay:3];
代理方法:
[cpp] view plaincopy
-
#pragma mark -
-
#pragma mark HUD的代理方法,关闭HUD时执行
-
-(void)hudWasHidden:(MBProgressHUD *)hud
-
{
-
[hud removeFromSuperview];
-
[hud release];
-
hud = nil;
-
}
-
SVProgressHUD和MBProgressHUD效果差不多,不过不需要使用协议,同时也不需要声明实例。
显示 HUD
您可以使用下面的方法中的任意一个来显示HUD,以及指示任务的状态:
+ (void)show;
+ (void)showWithStatus:(NSString*)string;
如果您想在HUD指示任务的进度,请使用下列操作之一:
+ (void)showProgress:(CGFloat)progress;
+ (void)showProgress:(CGFloat)progress status:(NSString*)status;
隐藏 HUD
HUD可以用以下方法隐藏:
+ (void)dismiss;
+ (void)dismissWithDelay:(NSTimeInterval)delay;
如果你想显示多个HUD ,可以使用使用一下方法:
+ (void)popActivity;
该HUD将自动消失, popActivity
将与显示的次数匹配。
显示一个提示消息
也可以用于显示一个提示信息。所述显示时间取决于给定的字符串的长度( 0.5至5秒)。
+ (void)showInfoWithStatus:(NSString *)string;
+ (void)showSuccessWithStatus:(NSString*)string;
+ (void)showErrorWithStatus:(NSString *)string;
+ (void)showImage:(UIImage*)image status:(NSString*)string;
自定义
SVProgressHUD
可通过下列方法进行个性化定制:
+ (void)setDefaultStyle:(SVProgressHUDStyle)style; // 默认是SVProgressHUDStyleLight
+ (void)setDefaultMaskType:(SVProgressHUDMaskType)maskType; // 默认是SVProgressHUDMaskTypeNone
+ (void)setDefaultAnimationType:(SVProgressHUDAnimationType)type; // 默认是 SVProgressHUDAnimationTypeFlat
+ (void)setRingThickness:(CGFloat)width; // 默认是 2 pt
+ (void)setCornerRadius:(CGFloat)cornerRadius; // 默认是 14 pt
+ (void)setFont:(UIFont*)font; // 默认是 [UIFont preferredFontForTextStyle:UIFontTextStyleSubheadline]
+ (void)setForegroundColor:(UIColor*)color; // 默认是 [UIColor blackColor], 仅对 SVProgressHUDStyleCustom 有效
+ (void)setBackgroundColor:(UIColor*)color; // 默认是 [UIColor whiteColor], 仅对 SVProgressHUDStyleCustom 有效
+ (void)setInfoImage:(UIImage*)image; //默认是bundle文件夹中的提示图片.
+ (void)setSuccessImage:(UIImage*)image; // 默认是bundle文件夹中的成功图片.
+ (void)setErrorImage:(UIImage*)image; // 默认是bundle文件夹中的错误图片.
+ (void)setViewForExtension:(UIView*)view; // 默认是nil,仅当设置了 #define SV_APP_EXTENSIONS 时有效.
通知
SVProgressHUD
通过 NSNotificationCenter
注册4份通知,以响应正在显示/消失:
-
SVProgressHUDWillAppearNotification
提示框即将出现 -
SVProgressHUDDidAppearNotification
提示框已经出现 -
SVProgressHUDWillDisappearNotification
提示框即将消失 -
SVProgressHUDDidDisappearNotification
提示框已经消失
每个通知传递一个 userInfo
字典,字典中包含HUD的状态字符串(如果有的话) ,可通过 SVProgressHUDStatusUserInfoKey
作为键来获取。
SVProgressHUD
还发送通知: SVProgressHUDDidReceiveTouchEventNotification
当用户触摸整体屏幕上 和
' SVProgressHUDDidTouchDownInsideNotification当用户直接在HUD接触。这两个通知没有
userInfo参数,但包含了有关的触摸的
UIEvent` 参数.