ios几秒之后自动消失的提示框

2019-10-16  本文已影响0人  滴滴滴开门

第一步:首先当然是封装起来,方便下次直接调用。我直接一个继承UIView的类

如图

//调用这个方法必须是要在s控制器视图加载完成之后才能调用,不然会出现错误。

+(void)showAlertMessageWithMessage:(NSString*)message duration:(NSTimeInterval)time AlertController:(UIViewController*)cell;

+(void) dimissAlert:(UIAlertController*)alert;

第二步就是去.m文件实现方法

+(void)showAlertMessageWithMessage:(NSString*)message duration:(NSTimeInterval)time AlertController:(UIViewController*)cell;

{

    UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:message preferredStyle:UIAlertControllerStyleAlert];

    [cellpresentViewController:alert animated:YES completion:nil];

    //控制提示框显示的时间为2秒

    [self performSelector:@selector(dismiss:) withObject:alert afterDelay:time];

}

+(void) dismiss:(UIAlertController*)alert;

{

        if(alert)    {

            [alertdismissViewControllerAnimated:YES completion:nil];

        }

}

第三步就是去你想要在哪个个控制器调用的直接

 [MProgressHub showAlertMessageWithMessage:@"111111" duration:10 AlertController:self];

就是这样,没错就是这么简单。。。看人家写的一堆堆。。还不如自己写个简单合用的。谢谢。

上一篇 下一篇

猜你喜欢

热点阅读