1)使用场景
项目工程中,时常用到弹框提示,基于MBProgressHUD简单封装的实用弹框提示。
2)源码分享
//基于MBProgressHUD,故使用前,请自行导入MBProgressHUD三方库
+ (void)showMessageWithTitle:(NSString *)title withContent:(NSString *)content withDelay:(NSTimeInterval)delay
{
dispatch_async(dispatch_get_main_queue(), ^{
MBProgressHUD *progressView = [MBProgressHUD showHUDAddedTo:[UIApplication sharedApplication].keyWindow animated:YES];
progressView.bezelView.color = [UIColor darkGrayColor];
progressView.bezelView.style = MBProgressHUDBackgroundStyleSolidColor;
progressView.contentColor = [UIColor whiteColor];
progressView.mode = MBProgressHUDModeText;
progressView.label.text = title;
progressView.detailsLabel.text = content;
[progressView hideAnimated:YES afterDelay:delay];
});
}
3)使用方法
//带Title或不带Title,文字自适应
[MessageUtil showMessageWithTitle:@"Title" withContent:@"字数自适应测试" withDelay:2];
网友评论