123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- //
- // MBProgressHUD+Extension.m
- // djlt
- //
- // Created by macmini04 on 16/1/18.
- // Copyright © 2016年 com.topsage.djlt. All rights reserved.
- //
- #import "MBProgressHUD+Extension.h"
- @implementation MBProgressHUD (Extension)
- + (instancetype)showLoadingAddedToView:(UIView *)view {
- MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
- hud.labelText = @"加载中";
- hud.labelFont = [UIFont boldSystemFontOfSize:17];
- hud.backgroundColor = [UIColor KXColorWithHex:0x000000 alpha:0.3];
-
- return hud;
- }
- + (instancetype)showTip:(NSString *)tip {
- MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:[UIApplication sharedApplication].keyWindow animated:YES];
-
- hud.mode = MBProgressHUDModeText;
- hud.labelText = tip;
- hud.labelFont = [UIFont boldSystemFontOfSize:17];
- hud.backgroundColor = [UIColor KXColorWithHex:0x000000 alpha:0.3];
- [hud hide:YES afterDelay:0.75];
- return hud;
- }
- /** 显示信息 */
- + (MBProgressHUD *)showMessage:(NSString *)message {
- return [self showMessage:message toView:nil];
- }
- + (MBProgressHUD *)showMessage:(NSString *)message toView:(UIView *)view {
- if (view == nil) view = [[UIApplication sharedApplication].windows lastObject];
-
- // 快速显示一个提示信息
- MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
- hud.labelText = message;
- hud.mode =MBProgressHUDModeText;
- // 隐藏时候从父控件中移除
- hud.removeFromSuperViewOnHide = YES;
-
- // 1秒之后再消失
- [hud hide:YES afterDelay:2];
- return hud;
- }
- + (void)show:(NSString *)text icon:(NSString *)icon view:(UIView *)view {
- if (view == nil) view = [[UIApplication sharedApplication].windows lastObject];
-
- // 快速显示一个提示信息
- MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
- hud.labelText = text;
- // 设置图片
- hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"MBProgressHUD.bundle/%@", icon]]];
- // 再设置模式
- hud.mode = MBProgressHUDModeCustomView;
-
- // hud.mode = MBProgressHUDModeAnnularDeterminate; // 圆形进度条
-
- // 隐藏时候从父控件中移除
- hud.removeFromSuperViewOnHide = YES;
-
- // 1秒之后再消失
- [hud hide:YES afterDelay:1];
- }
- /** 成功 */
- + (void)showSuccess:(NSString *)success {
- [self showSuccess:success toView:nil];
- }
- + (void)showSuccess:(NSString *)success toView:(UIView *)view
- {
- [self show:success icon:@"success.png" view:view];
- }
- /** 错误 */
- + (void)showError:(NSString *)error {
- [self showError:error toView:nil];
- }
- + (void)showError:(NSString *)error toView:(UIView *)view{
- [self show:error icon:@"error.png" view:view];
- }
- /** 隐藏 */
- + (void)hideHUD {
- [self hideHUDForView:nil];
- }
- + (void)hideHUDForView:(UIView *)view {
- if (view == nil) view = [[UIApplication sharedApplication].windows lastObject];
- // 隐藏时候从父控件中移除
- [self hideHUDForView:view animated:YES];
-
- }
- @end
|