美文网首页
对MBProgressHUD的封装

对MBProgressHUD的封装

作者: 精神薇 | 来源:发表于2018-10-12 15:16 被阅读0次
/**
 *  显示成功信息
 *
 *  @param success 信息内容
 *  @param view    显示信息的视图
 */
+ (void)showSuccess:(NSString *)success toView:(UIView *)view
{
    [self show:success icon:@"Checkmark.png" view:view];
}
/**
 *  显示错误信息
 *
 *  @param error 错误信息内容
 *  @param view  需要显示信息的视图
 */
+ (void)showError:(NSString *)error toView:(UIView *)view{
    [self show:error icon:@"error.png" view:view];
}
/**
 *  显示信息
 *
 *  @param text 信息内容
 *  @param icon 图标
 *  @param view 显示的视图
 */
+ (void)show:(NSString *)text icon:(NSString *)icon view:(UIView *)view
{
    if (view == nil) view = [UIApplication sharedApplication].delegate.window;
    NeuProgressHUD *hud = [NeuProgressHUD showHUDAddedTo:view animated:YES];
    
    // Set the custom view mode to show any view.
    hud.mode = NeuProgressHUDModeCustomView;
    // Set an image view with a checkmark.
    UIImage *image = [[UIImage imageNamed:[NSString stringWithFormat:@"NeuRecord.bundle/%@", icon]] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
    hud.customView = [[UIImageView alloc] initWithImage:image];
    // Looks a bit nicer if we make it square.
    hud.square = YES;
    // Optional label text.
    hud.label.text = text;
    
    [hud hideAnimated:YES afterDelay:2.f];
}
/**
 *  底部提示信息
 *
 *  @param message 信息内容
 *  @param view 显示的视图
 */
+(void)showText:(NSString *)message withView:(UIView *)view{
    if (view == nil) view = [UIApplication sharedApplication].delegate.window;
    NeuProgressHUD *hud = [NeuProgressHUD showHUDAddedTo:view animated:YES];
    hud.mode = NeuProgressHUDModeText;
    hud.label.text = message;
    // Move to bottm center.
    hud.offset = CGPointMake(0.f, NeuProgressMaxOffset);
    [hud hideAnimated:YES afterDelay:2.f];
}
/**
 *
 *   网络请求加载等待
 *  @param message 加载中
 *  @param view 显示的视图
 */
+ (NeuProgressHUD *)showMessage:(NSString *)message toView:(UIView *)view{
    if (view == nil) view = [UIApplication sharedApplication].delegate.window;
    NeuProgressHUD *hud = [NeuProgressHUD showHUDAddedTo:view animated:YES];
    
    // Set the label text.
    hud.label.text = message;
    return hud;
}
+ (void)hideHUDForView:(UIView *)view{
    if (view == nil) view = [UIApplication sharedApplication].delegate.window;
    [self hideHUDForView:view animated:YES];
}

相关文章

网友评论

      本文标题:对MBProgressHUD的封装

      本文链接:https://www.haomeiwen.com/subject/tplgaftx.html