• hud控件的使用 SVprogressHud MBProgressHUD


    1. //方式1.直接在View上show  

    2. HUD = [[MBProgressHUD showHUDAddedTo:self.view animated:YES] retain];  

    3. HUD.delegate = self;  

    4.   

    5. //常用的设置  

    6. //小矩形的背景色  

    7. HUD.color = [UIColor clearColor];//这儿表示无背景  

    8. //显示的文字  

    9. HUD.labelText = @"Test";  

    10. //细节文字  

    11. HUD.detailsLabelText = @"Test detail";  

    12. //是否有庶罩  

    13. HUD.dimBackground = YES;  

    14. [HUD hide:YES afterDelay:2];  

    15.   

    16. //只显示文字  

    17. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];  

    18. hud.mode = MBProgressHUDModeText;  

    19. hud.labelText = @"Some message...";  

    20. hud.margin = 10.f;  

    21. hud.yOffset = 150.f;  

    22. hud.removeFromSuperViewOnHide = YES;  

    23. [hud hide:YES afterDelay:3];  

    24.   

    25. //方式2.initWithView  

    26. //use block  

    27. HUD = [[MBProgressHUD alloc] initWithView:self.view];  

    28. [self.view addSubview:HUD];  

    29. HUD.labelText = @"Test";  

    30. [HUD showAnimated:YES whileExecutingBlock:^{  

    31.     NSLog(@"%@",@"do somethings....");  

    32.     [self doTask];  

    33. } completionBlock:^{  

    34.     [HUD removeFromSuperview];  

    35.     [HUD release];          

    36. }];  

    37.   

    38. //圆形进度条  

    39. HUD = [[MBProgressHUD alloc] initWithView:self.view];  

    40. [self.view addSubview:HUD];  

    41. HUD.mode = MBProgressHUDModeAnnularDeterminate;  

    42. HUD.delegate = self;  

    43. HUD.labelText = @"Loading";  

    44. [HUD showWhileExecuting:@selector(myProgressTask) onTarget:self withObject:nil animated:YES];  

    45.   

    46. //自定义view  

    47. HUD = [[MBProgressHUD alloc] initWithView:self.view];  

    48. HUD.customView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"37x-Checkmark.png"]] autorelease];  

    49. // Set custom view mode  

    50. HUD.mode = MBProgressHUDModeCustomView;  

    51. HUD.delegate = self;  

    52. HUD.labelText = @"Completed";  

    53. [HUD show:YES];  

    54. [HUD hide:YES afterDelay:3];  

    代理方法:

    [cpp] view plaincopy

    1. #pragma mark -  

    2. #pragma mark HUD的代理方法,关闭HUD时执行  

    3. -(void)hudWasHidden:(MBProgressHUD *)hud  

    4. {  

    5.     [hud removeFromSuperview];  

    6.     [hud release];  

    7.     hud = nil;  

    8. }  

    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` 参数.

  • 相关阅读:
    DB2 导入CSV文件
    非归档模式下丢失数据文件,怎么办
    制作U盘操作系统安装盘
    Oracle 发布 NoSQL 数据库
    【转载】VMWare Workstation 支持64位操作系统
    net下多个应用之间的web.config冲突的解决办法(禁止继承)
    \r\n 的真切含义
    VMware虚拟机中调整Linux分区大小手记
    磨刀不光不误切菜功,还能强身健体
    农夫送狼羊白菜过河_题目收集
  • 原文地址:https://www.cnblogs.com/yecong/p/6029300.html
Copyright © 2020-2023  润新知