MBProgressHUD的基本用法

来源:互联网 发布:大路口车流量数据 编辑:程序博客网 时间:2024/06/07 05:01

////创建MBProgressHUD提示

-(void)MBProgressHUD{


    

   ///////1///   self指的是HUD要显示在那个view上

//    //方式1.直接在Viewshow

//  MBProgressHUD*  HUD = [MBProgressHUD showHUDAddedTo:self animated:YES];

//    //常用的设置

//    //小矩形的背景色

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

//    //显示的文字

//    HUD.labelText = @"发送消息成功";

//    //细节文字

//    HUD.detailsLabelText = @"socket消息";

//    //是否有庶罩

//    HUD.dimBackground = YES;

//    [HUD hide:YES afterDelay:5];

    

////2//只显示文字

    MBProgressHUD *hud = [MBProgressHUDshowHUDAddedTo:selfanimated:YES];

    hud.mode =MBProgressHUDModeText;//显示的模式

    hud.labelText =@"发送消息成功";

    hud.labelColor=[UIColorredColor];

    hud.margin =10.f;//文字和背景的距离

    hud.yOffset =200.f;//整个MBViewY的位置(起点位置是在view的中心附近)

    hud.xOffset=10.0;//整个MBViewX的位置

    hud.removeFromSuperViewOnHide =YES;  

    [hud hide:YESafterDelay:2];


    

///3/////

    //方式2.initWithView

    //use block

//      MBProgressHUD* HUD = [[MBProgressHUD alloc] initWithView:self];

//    [self addSubview:HUD];

//    HUD.labelText = @"发送消息成功";

//    HUD.mode=MBProgressHUDModeAnnularDeterminate;//模式带小圆圈

//    [HUD showAnimated:YES whileExecutingBlock:^{

//        sleep(3);

//    } completionBlock:^{

//

//    }];

    

// 3/ 水平进度条

//   MBProgressHUD* HUD = [[MBProgressHUD alloc] initWithView:self];

//    [self addSubview:HUD];

//    HUD.mode = MBProgressHUDModeDeterminateHorizontalBar;//水平进度条

//    HUD.labelText = @"发送消息成功";

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

    

///4  //  //自定义view

//   MBProgressHUD* HUD = [[MBProgressHUD alloc] initWithView:self];

//    HUD.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"newfor"]];

//    [self addSubview:HUD];

//    HUD.mode = MBProgressHUDModeCustomView;

//    HUD.labelText = @"发送消息成功";

//    [HUD show:YES];  

//    [HUD hide:YES afterDelay:3];  

 UIWindow *window = [UIApplicationsharedApplication].keyWindow;

        [MBProgressHUDhideAllHUDsForView:windowanimated:YES];

        _hud = [MBProgressHUDshowHUDAddedTo:window animated:YES]


    

}

//-(void)myProgressTask{

//    sleep(3);

//}


0 0
原创粉丝点击