欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

(转)【iOS】类Android Toast风格提示

程序员文章站 2022-05-07 18:18:02
...

 转自:https://my.oschina.net/liyang2l/blog/204767

 

MBProgressHUD是一个开源项目,实现了很多种样式的提示框

https://github.com/jdg/MBProgressHUD,下载下来后直接把MBProgressHUD.h和MBProgressHUD.m加入即可。

运行效果如下 和android toast 类似

-(void)showAllTextDialog:(NSString *)str
{
    HUD = [[MBProgressHUD alloc] initWithView:self.view];
    [self.view addSubview:HUD];
    HUD.labelText = str;
    HUD.mode = MBProgressHUDModeText;
    
    //指定距离中心点的X轴和Y轴的位置,不指定则在屏幕中间显示
    //    HUD.yOffset = 100.0f;
    //    HUD.xOffset = 100.0f;
    
    [HUD showAnimated:YES whileExecutingBlock:^{
        sleep(1);
    } completionBlock:^{
        [HUD removeFromSuperview];
//        [HUD release];
        HUD = nil;
    }];
    
}

 

 

(转)【iOS】类Android Toast风格提示
            
    
    博客分类: IOS Toast提示 

 

 

附上我自定义的方法:

+(void)showToast:(UIView *)view content:(NSString *)text{
    
    __block MBProgressHUD *hud = [[MBProgressHUD alloc] initWithView:view];
    [view addSubview:hud];
    hud.mode = MBProgressHUDModeText;
    
    hud.label.text = text;
    hud.label.textColor = [UIColor whiteColor];
    //换行
    hud.label.lineBreakMode = UILineBreakModeWordWrap;
    hud.label.numberOfLines = 0;

    [hud setColor:[UIColor blackColor]];
    
    CGRect screen = [UIScreen mainScreen].bounds;
    NSLog(@"width:%f,height:%f",screen.size.width,screen.size.height);
    
    hud.yOffset = screen.size.height - 100.0f;
    
    //指定距离中心点的X轴和Y轴的位置,不指定则在屏幕中间显示
//    hud.yOffset = 300.0f;
    //    hud.xOffset = 100.0f;
    
    [hud showAnimated:YES whileExecutingBlock:^{
        sleep(1.5);
    } completionBlock:^{
        [hud removeFromSuperview];
        //        [HUD release];
        hud = nil;
    }];
}

 

相关标签: Toast 提示