• iOS -- MBProgressHUB


    高级http://www.jianshu.com/p/485b8d75ccd4

    //只有小菊花

    - (void)indeterminateExample {

        // Show the HUD on the root view (self.view is a scrollable table view and thus not suitable,

        // as the HUD would move with the content as we scroll).

        MBProgressHUD *hud = [MBProgressHUDshowHUDAddedTo:self.navigationController.view animated:YES];

     

        // Fire off an asynchronous task, giving UIKit the opportunity to redraw wit the HUD added to the

        // view hierarchy.

        dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INITIATED0), ^{

     

            // Do something useful in the background

            [self doSomeWork];

     

            // IMPORTANT - Dispatch back to the main thread. Always access UI

            // classes (including MBProgressHUD) on the main thread.

            dispatch_async(dispatch_get_main_queue(), ^{

                [hud hideAnimated:YES];

            });

        });

    }

     

    //小菊花+文字

    - (void)labelExample {

        MBProgressHUD *hud = [MBProgressHUDshowHUDAddedTo:self.navigationController.view animated:YES];

     

        // Set the label text.

        hud.label.text = NSLocalizedString(@"Loading..."@"HUD loading title");

        // You can also adjust other label properties if needed.

        // hud.label.font = [UIFont italicSystemFontOfSize:16.f];

     

        dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INITIATED0), ^{

            [self doSomeWork];

            dispatch_async(dispatch_get_main_queue(), ^{

                [hud hideAnimated:YES];

            });

        });

    }

    //小菊花+文字+detailsLabel

    - (void)detailsLabelExample {

        MBProgressHUD *hud = [MBProgressHUDshowHUDAddedTo:self.navigationController.view animated:YES];

     

        // Set the label text.

        hud.label.text = NSLocalizedString(@"Loading..."@"HUD loading title");

        // Set the details label text. Let's make it multiline this time.

        hud.detailsLabel.text = NSLocalizedString(@"Parsing data (1/1)"@"HUD title");

     

        dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INITIATED0), ^{

            [self doSomeWork];

            dispatch_async(dispatch_get_main_queue(), ^{

                [hud hideAnimated:YES];

            });

        });

    }

     

    - (void)windowExample {

        // Covers the entire screen. Similar to using the root view controller view.

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

        dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INITIATED0), ^{

            [self doSomeWork];

            dispatch_async(dispatch_get_main_queue(), ^{

                [hud hideAnimated:YES];

            });

        });

    }

    //圆环进度条+文字

    - (void)determinateExample {

        MBProgressHUD *hud = [MBProgressHUDshowHUDAddedTo:self.navigationController.view animated:YES];

     

        // Set the determinate mode to show task progress.

        hud.mode = MBProgressHUDModeDeterminate;

        hud.label.text = NSLocalizedString(@"Loading..."@"HUD loading title");

     

        dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INITIATED0), ^{

            // Do something useful in the background and update the HUD periodically.

            [self doSomeWorkWithProgress];

            dispatch_async(dispatch_get_main_queue(), ^{

                [hud hideAnimated:YES];

            });

        });

    }

    //圆环进度条+文字取消按钮

    - (void)determinateNSProgressExample {

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

     

    // Set the determinate mode to show task progress.

    hud.mode = MBProgressHUDModeDeterminate;

    hud.label.text = NSLocalizedString(@"Loading...", @"HUD loading title");

     

    // Set up NSProgress

    NSProgress *progressObject = [NSProgress progressWithTotalUnitCount:100];

    hud.progressObject = progressObject;

     

    // Configure a cancel button.

    [hud.button setTitle:NSLocalizedString(@"Cancel", @"HUD cancel button title") forState:UIControlStateNormal];

    [hud.button addTarget:progressObject action:@selector(cancel) forControlEvents:UIControlEventTouchUpInside];

     

    dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0), ^{

    // Do something useful in the background and update the HUD periodically.

    [self doSomeWorkWithProgressObject:progressObject];

    dispatch_async(dispatch_get_main_queue(), ^{

    [hud hideAnimated:YES];

    });

    });

    }

    //圆环进度条+文字

    - (void)annularDeterminateExample {

        MBProgressHUD *hud = [MBProgressHUDshowHUDAddedTo:self.navigationController.view animated:YES];

     

        // Set the annular determinate mode to show task progress.

        hud.mode = MBProgressHUDModeAnnularDeterminate;

        hud.label.text = NSLocalizedString(@"Loading..."@"HUD loading title");

     

        dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INITIATED0), ^{

            // Do something useful in the background and update the HUD periodically.

            [self doSomeWorkWithProgress];

            dispatch_async(dispatch_get_main_queue(), ^{

                [hud hideAnimated:YES];

            });

        });

    }

    //直线进度条+文字

    - (void)barDeterminateExample {

        MBProgressHUD *hud = [MBProgressHUDshowHUDAddedTo:self.navigationController.view animated:YES];

     

        // Set the bar determinate mode to show task progress.

        hud.mode = MBProgressHUDModeDeterminateHorizontalBar;

        hud.label.text = NSLocalizedString(@"Loading..."@"HUD loading title");

     

        dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INITIATED0), ^{

            // Do something useful in the background and update the HUD periodically.

            [self doSomeWorkWithProgress];

            dispatch_async(dispatch_get_main_queue(), ^{

                [hud hideAnimated:YES];

            });

        });

    }

    #pragma mark --自定义视图

    //自定义视图

    - (void)customViewExample {

        MBProgressHUD *hud = [MBProgressHUDshowHUDAddedTo:self.navigationController.view animated:YES];

     

        // Set the custom view mode to show any view.

        hud.mode = MBProgressHUDModeCustomView;

        // Set an image view with a checkmark.

        //default

    //    UIImage *image = [[UIImage imageNamed:@"Checkmark"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];

        

        //mxs

        //UIImage *image = [[UIImage imageNamed:@"下拉刷新一80x80"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];//success  下拉刷新一80x80密码登录lgo

        

        UIImage *image = [UIImage imageNamed:@"下拉刷新一80x80"];//success  下拉刷新一80x80 密码登录lgo

     

        UIImageView *imgV = [[UIImageView allocinitWithImage:image];

        

        [imgV.layer addAnimation:[self makeRotationforKey:nil];

      

        hud.customView = imgV;

        // Looks a bit nicer if we make it square.

        hud.square = YES;

        // Optional label text.

        hud.label.text = @"Done"

     

        [hud hideAnimated:YES afterDelay:2.f];//几秒后消失

    }

     

     

    #pragma mark --旋转

    - (CABasicAnimation *)makeRotation{

        

        CATransform3D rotationTransform =CATransform3DMakeRotation((360*180.0)/(M_PI), 00, -1);

        CABasicAnimation *animation = [CABasicAnimationanimationWithKeyPath:@"transform"];

        animation.toValue = [NSValue valueWithCATransform3D:rotationTransform];

        animation.duration  =  1;

        animation.autoreverses = NO;

        animation.cumulative = YES;

        animation.fillMode = kCAFillModeForwards;

        animation.repeatCount = 100;

        

        return animation;

    }

     

    //只有文字

    - (void)textExample {

        MBProgressHUD *hud = [MBProgressHUDshowHUDAddedTo:self.navigationController.view animated:YES];

     

        // Set the text mode to show only text.

        hud.mode = MBProgressHUDModeText;

        hud.label.text = NSLocalizedString(@"Message here!"@"HUD message title");

        // Move to bottm center.

        hud.offset = CGPointMake(0.fMBProgressMaxOffset);

     

        [hud hideAnimated:YES afterDelay:3.f];

    }

     

    - (void)cancelationExample {

        MBProgressHUD *hud = [MBProgressHUDshowHUDAddedTo:self.navigationController.view animated:YES];

     

        // Set the determinate mode to show task progress.

        hud.mode = MBProgressHUDModeDeterminate;

        hud.label.text = NSLocalizedString(@"Loading..."@"HUD loading title");

     

        // Configure the button.

        [hud.button setTitle:NSLocalizedString(@"Cancel"@"HUD cancel button title"forState:UIControlStateNormal];

        [hud.button addTarget:self action:@selector(cancelWork:)forControlEvents:UIControlEventTouchUpInside];

     

        dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INITIATED0), ^{

            // Do something useful in the background and update the HUD periodically.

            [self doSomeWorkWithProgress];

            dispatch_async(dispatch_get_main_queue(), ^{

                [hud hideAnimated:YES];

            });

        });

    }

    //小菊花--转换-->圆环

    - (void)modeSwitchingExample {

        MBProgressHUD *hud = [MBProgressHUDshowHUDAddedTo:self.navigationController.view animated:YES];

     

        // Set some text to show the initial status.

        hud.label.text = NSLocalizedString(@"Preparing..."@"HUD preparing title");

        // Will look best, if we set a minimum size.

        hud.minSize = CGSizeMake(150.f100.f);

     

        dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INITIATED0), ^{

            // Do something useful in the background and update the HUD periodically.

            [self doSomeWorkWithMixedProgress];

            dispatch_async(dispatch_get_main_queue(), ^{

                [hud hideAnimated:YES];

            });

        });

    }

     

    - (void)networkingExample {

        MBProgressHUD *hud = [MBProgressHUDshowHUDAddedTo:self.navigationController.view animated:YES];

     

        // Set some text to show the initial status.

        hud.label.text = NSLocalizedString(@"Preparing..."@"HUD preparing title");

        // Will look best, if we set a minimum size.

        hud.minSize = CGSizeMake(150.f100.f);

     

        [self doSomeNetworkWorkWithProgress];

    }

     

    - (void)dimBackgroundExample {

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

     

    // Change the background view style and color.

    hud.backgroundView.style = MBProgressHUDBackgroundStyleSolidColor;

    hud.backgroundView.color = [UIColor colorWithWhite:0.f alpha:0.1f];

     

    dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0), ^{

    [self doSomeWork];

    dispatch_async(dispatch_get_main_queue(), ^{

    [hud hideAnimated:YES];

    });

    });

    }

     

    - (void)colorExample {

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

    hud.contentColor = [UIColor colorWithRed:0.f green:0.6f blue:0.7f alpha:1.f];

     

    // Set the label text.

    hud.label.text = NSLocalizedString(@"Loading...", @"HUD loading title");

     

    dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0), ^{

    [self doSomeWork];

    dispatch_async(dispatch_get_main_queue(), ^{

    [hud hideAnimated:YES];

    });

    });

    }

    #pragma mark - Tasks

     

    - (void)doSomeWork {

        // Simulate by just waiting.

        sleep(3.);

    }

  • 相关阅读:
    前端+php实现概率抽奖
    rem.js的用法及在浏览器端的适配
    python 使用记录及问题
    python 工具链 虚拟环境和包管理工具 pipenv
    python 工具链 多版本管理工具 pyenv
    python 工具链 包管理工具 pip
    ansible 使用记录
    mongodb connection refused because too many open connections: 819
    wordpress 常用操作
    服务器硬件测试
  • 原文地址:https://www.cnblogs.com/mafeng/p/7324752.html
Copyright © 2020-2023  润新知