有时候我们只需要简单的弹窗提醒,并不需要MBProgressHUD大材小用.
但是弹窗提醒除了提醒的内容每次不一样,其他的都一样,每次写起来难免有些烦躁
接下来我就把它写成宏,以后只需要一行代码就搞定,看着特别简洁
// 这是常规的写法,每次都要重复写一次 UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"title" message:@"content" preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"好的" style:UIAlertActionStyleDefault handler:nil]; [alertController addAction:okAction]; [self presentViewController:alertController animated:YES completion:nil];
// 抽成宏之后,只需要一行代码就能完成弹窗提醒 #define alert(string, detail) UIAlertController *alertController = [UIAlertController alertControllerWithTitle:string message:detail preferredStyle:UIAlertControllerStyleAlert]; \ UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"好的" style:UIAlertActionStyleDefault handler:nil]; \ [alertController addAction:okAction]; \ [self presentViewController:alertController animated:YES completion:nil];
// 调用它只需一行代码 alert(@"提交成功", @"终于成功了") 或者alert(@"提交失败", nil)