iOS MBProgressHUD 常用的四种方式

效果一 只显示文字:

冯绍峰粉色粉色.gif

// 只显示文字- (void)TextButtonAction{self.HUD = [[MBProgressHUD alloc] initWithView:self.view];    [self.view addSubview:_HUD];    _HUD.labelText =@"加载中,请稍等...";    _HUD.mode = MBProgressHUDModeText;        [_HUD showAnimated:YESwhileExecutingBlock:^{        sleep(2);            }      completionBlock:^{          [_HUD removeFromSuperview];          _HUD =nil;      }];}


效果二  圆形进度条

冯绍峰粉色粉色.gif

// 圆形进度条- (void)CircularButtonAction{//圆形进度条self.HUD = [[MBProgressHUD alloc] initWithView:self.view];        [self.view addSubview:_HUD];        _HUD.mode = MBProgressHUDModeDeterminate;        _HUD.delegate =self;        _HUD.labelText =@"等待中";        [_HUD showWhileExecuting:@selector(ProgressBar) onTarget:selfwithObject:nilanimated:YES];}//  进度条  计算- (void)ProgressBar{// 进度指示器,从0.0到1.0,默认值为0.0floatprogress =0.0f;while(progress <1.0f) {                progress +=0.01f;                _HUD.progress = progress;//        usleep函数能把进程挂起一段时间, 单位是微秒(千分之一毫秒)usleep(50000);    }}


效果三  文字 加 菊花

冯绍峰粉色粉色.gif

//  通常情况  文字  加 菊花- (void)GeneralButtonAction{//初始化进度框,置于当前的View当中self.HUD = [[MBProgressHUD alloc] initWithView:self.view];    [self.view addSubview:_HUD];//如果设置此属性则当前的view置于后台_HUD.dimBackground =YES;//设置对话框文字_HUD.labelText =@"加载中";//细节文字_HUD.detailsLabelText =@"请耐心等待";//显示对话框[_HUD showAnimated:YESwhileExecutingBlock:^{//对话框显示时需要执行的操作sleep(3);    }// 在HUD被隐藏后的回调completionBlock:^{//操作执行完后取消对话框[_HUD removeFromSuperview];          _HUD =nil;    }];}


效果四  自定义动图

冯绍峰粉色粉色.gif

//  自定义 动图- (void)CustomButtonAction{//自定义viewself.HUD = [[MBProgressHUD alloc] initWithView:self.view];//取消背景框self.HUD.color = [UIColorwhiteColor];        [self.view addSubview:_HUD];UIImageView*images = [[UIImageViewalloc]initWithFrame:CGRectMake(0,0,200,300)];NSMutableArray*imageArray = [[NSMutableArrayalloc]init];for(inti =1; i <8; i++){NSString*imgName = [NSStringstringWithFormat:@"%d.tiff",i];                [imageArray addObject:[UIImageimageNamed:imgName]];    }        images.animationDuration =0.7;        images.animationImages = imageArray;// 开始播放[images startAnimating];//自定义_HUD.mode = MBProgressHUDModeCustomView;    _HUD.delegate =self;        _HUD.customView = images;        [_HUD show:YES];//延迟[_HUD hide:YESafterDelay:2];    }

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • - (void)testMBProgressHUD { NSLog(@"test MBProgressHUD ")...
    有偶像包袱的程序狗阅读 5,464评论 0 1
  • 20180303,张红 今天进行了约练,很幸运,做了2次咨询师。 很有意思,我们一共3位张老师齐聚一堂。最开始呢是...
    啊呦a7_94阅读 1,046评论 0 0
  • LocalDate 获取系统当时日期: LocalDate.now();; 使用TemporalField读取Lo...
    宿命99阅读 3,902评论 1 1
  • 每个女孩子都有一个公主梦,期待与那个深情的王子从此幸福地生活在一起。 真真七八岁的时候,特别看爱童话故事,特别相信...
    夕雁无边阅读 1,118评论 0 1
  • 前言 clang提供了一些命令,让我们可以对编译的过程进行一些配置和查看,下面我们就对一些常用的指令进行一个基本的...
    sea_biscute阅读 29,307评论 0 18