| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178 |
- //
- // MBProgressHUD+YanC.m
- // BorrowMoney
- //
- // Created by chengzhang Yan on 2016/10/13.
- // Copyright © 2016年 JuYi. All rights reserved.
- //
- #import "MBProgressHUD+YanC.h"
- @implementation MBProgressHUD (YanC)
- #pragma mark 显示信息
- + (void)show:(NSString *)text icon:(NSString *)icon view:(UIView *)view {
-
- if (view == nil) view = [UIApplication sharedApplication].keyWindow;
- MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
- hud.label.text = text;
- hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"MBProgressHUD.bundle/%@", icon]]];
- [hud.bezelView setBackgroundColor:[UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:0.8]];
- hud.contentColor = [UIColor whiteColor];
- hud.mode = MBProgressHUDModeCustomView;
- hud.removeFromSuperViewOnHide = YES;
- [hud hideAnimated:YES afterDelay:2.0];
- }
- /** 显示成功 */
- + (void)showSuccess:(NSString *)success {
- [self showSuccess:success toView:nil];
- }
- /** 显示失败 */
- + (void)showError:(NSString *)error {
- [self showError:error toView:nil];
- }
- /** 显示提示符号 */
- + (void)showInfo:(NSString *)info {
- [self showInfo:info toView:nil];
- }
- /** 显示信息+转圈圈 */
- + (void)showMessage:(NSString *)message {
- [self showMessage:message toView:nil];
- }
- /** 显示图片 */
- + (void)showLogoImageWithImageName:(NSString *)imgName {
- [self showLogoImageWithImageName:imgName toView:nil];
- //只显示菊花。因为没有了 gif 之后可以再改
- // [self showMessage:nil toView:nil model:MBProgressHUDModeIndeterminate];
- }
- /** 只显示一条提示信息 */
- + (void)showOnlyText:(NSString *)message {
- [self showOnlyText:message toView:nil];
- }
- /** 显示成功--->到指定view */
- + (void)showSuccess:(NSString *)success toView:(UIView *)view {
- [self show:success icon:@"success.png" view:view];
- }
- /** 显示失败--->到指定view */
- + (void)showError:(NSString *)error toView:(UIView *)view {
- [self show:error icon:@"error.png" view:view];
- }
- /** 显示提示符号--->到指定view */
- + (void)showInfo:(NSString *)info toView:(UIView *)view {
- [self show:info icon:@"info.png" view:view];
- }
- /** 显示信息(转圈圈)--->到指定view */
- + (void)showMessage:(NSString *)message toView:(UIView *)view {
- if (view == nil) {
- [self showMessage:message toView:view model:MBProgressHUDModeText];
- } else {
- [self showMessage:message toView:view model:MBProgressHUDModeCustomView];
- }
-
- }
- /** 只显示一条提示信息--->到指定view */
- + (void)showOnlyText:(NSString *)message toView:(UIView *)view {
- [self showMessage:message toView:view model:MBProgressHUDModeText];
- }
- + (void)showMessage:(NSString *)message toView:(UIView *)view model:(MBProgressHUDMode)model {
- // if (view == nil) view = [[UIApplication sharedApplication].windows lastObject];
- if (view == nil) view = [UIApplication sharedApplication].keyWindow;
- // 快速显示一个提示信息
- MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
-
- hud.labelText = message;
- //模式
- hud.mode = model;
- // YES代表需要蒙版效果
- hud.dimBackground = YES;
- // hud.backgroundColor = [UIColor colorWithWhite:0.f alpha:.2f];
- // hud.backgroundView.style = MBProgressHUDBackgroundStyleSolidColor;
- // 隐藏时候从父控件中移除
- hud.removeFromSuperViewOnHide = YES;
- if (model == MBProgressHUDModeText) {
- // X秒之后再消失
- [hud hide:YES afterDelay:2.0];
-
- }
-
- if (model == MBProgressHUDModeIndeterminate) {
-
- [hud hide:YES afterDelay:30.0];
- }
-
-
-
- }
- /** 显示图片 --->到指定view */
- + (void)showLogoImageWithImageName:(NSString *)imageName toView:(UIView *)view {
-
- if (view == nil) view = [UIApplication sharedApplication].keyWindow;
- // if (view == nil) view = [[UIApplication sharedApplication].windows lastObject];
- //
- MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
-
- UIImageView *imgBgView = [[UIImageView alloc] init];
- imgBgView.center = hud.customView.center;
- imgBgView.image = [UIImage imageNamed:imageName];
- hud.customView = imgBgView;
- // hud.dimBackground = YES;
- // hud.backgroundColor = [UIColor colorWithWhite:0.f alpha:.2f];
- // hud.backgroundView.style = MBProgressHUDBackgroundStyleSolidColor;
- hud.square = YES;
- hud.removeFromSuperViewOnHide = YES;
- hud.animationType = MBProgressHUDAnimationZoom;
- hud.mode = MBProgressHUDModeCustomView;
- hud.margin = 45.0f;
- hud.minSize = CGSizeMake(44.0f, 44.0f);
- // 消失时间
- [hud hide:YES afterDelay:30.0];
- }
- /** 隐藏HUD */
- + (void)hideHUD {
- [self hideHUDForView:nil];
- }
- /** 隐藏--->指定view上的HUD */
- + (void)hideHUDForView:(UIView *)view {
- if (view == nil) view = [UIApplication sharedApplication].keyWindow;
- // if (view == nil) view = [[UIApplication sharedApplication].windows lastObject];
- [self hideHUDForView:view animated:YES];
- }
- /** 只显示一条提示信息带确定按钮 */ //新需求
- + (void)showOnlyText:(NSString *)message controller:(UIViewController *)controller {
- //
- dispatch_async(dispatch_get_main_queue(), ^{
- UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"温馨提示" message:message preferredStyle:(UIAlertControllerStyleAlert)];
-
- // 设置按钮
- UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"确定" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
-
- }];
-
- [alertController addAction:action1];
- [controller presentViewController:alertController animated:YES completion:nil];
- });
-
- }
- @end
|