- 继承自UIViewController
- IOS9.0之后正式取代UIActionsheet与UIAlertview
UIAlertController简单使用
UIAlertController *controller = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
[controller addAction:[UIAlertAction actionWithTitle:@"收藏" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"点击了[收藏]按钮");
}]];
[controller addAction:[UIAlertAction actionWithTitle:@"举报" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"点击了[举报]按钮");
}]];
[controller addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"点击了[取消]按钮");
}]];
// [controller addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
// textField.textColor = [UIColor redColor];
// }];
// 需要弹出控制器
[self.window.rootViewController presentViewController:controller animated:YES completion:nil];
UIAlertControllerStyleActionSheet实现指示器
- 效果同UIActionsheet
- 不可以加文本框
/** * UIAlertController的使用:UIAlertControllerStyleActionSheet */ - (void)useAlertController2 { UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"警告" message:@"确定要删除它?" preferredStyle:UIAlertControllerStyleActionSheet]; // 添加按钮 UIAlertAction *sure = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) { NSLog(@"点击了【确定】按钮"); }]; [alertController addAction:sure]; [alertController addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) { NSLog(@"点击了【取消】按钮"); }]]; [alertController addAction:[UIAlertAction actionWithTitle:@"随便" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { NSLog(@"点击了【随便】按钮"); }]]; // 在当前控制器上面弹出另一个控制器:alertController [self presentViewController:alertController animated:YES completion:nil]; }
UIAlertControllerStyleAlert实现指示器效果
- 效果同UIAlertview
/** * UIAlertController的使用:UIAlertControllerStyleAlert */ - (void)useAlertController { UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"警告" message:@"确定要删除它?" preferredStyle:UIAlertControllerStyleAlert]; // 添加按钮 UIAlertAction *sure = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) { NSLog(@"点击了【确定】按钮"); }]; [alertController addAction:sure]; [alertController addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) { NSLog(@"点击了【取消】按钮"); }]]; // 添加文本框 [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) { textField.textColor = [UIColor redColor]; textField.secureTextEntry = YES; // 暗文 textField.placeholder = @"请输入密码"; }]; // 在当前控制器上面弹出另一个控制器:alertController [self presentViewController:alertController animated:YES completion:nil]; }
SVProgressHUD实现指示器效果
-
SVProgressHUD使用简单示例
/** * SVProgressHUD */ - (void)sv { // 下面这些消息需要主动调用dismiss方法来隐藏 // [SVProgressHUD show]; // [SVProgressHUD showWithMaskType:SVProgressHUDMaskTypeBlack]; // 增加灰色蒙板 // [SVProgressHUD showWithStatus:@"正在加载中..."]; // 下面这些消息会自动消失 // [SVProgressHUD showInfoWithStatus:@"数据加载完毕!"]; // [SVProgressHUD showSuccessWithStatus:@"成功加载到4条新数据!"]; [SVProgressHUD showErrorWithStatus:@"网络错误,请稍等!"]; // 延迟2秒后做一些事情 // dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ // [SVProgressHUD dismiss]; // }); }
MBProgressHUD实现指示器效果
- MBProgressHUD源码解释
- MBProgressHUD功能扩展
- MBProgressHUD使用简单示例
//计时器配合加载效果 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(changeProgress) userInfo:nil repeats:YES]; } double progress = 0.0; - (void)changeProgress { progress += 0.1; [SVProgressHUD showProgress:progress status:[NSString stringWithFormat:@"已下载%.0f%%", progress * 100]]; } /** * MBProgressHUD */ - (void)mb { MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES]; hud.labelText = @"正在加载中"; hud.removeFromSuperViewOnHide = YES; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [hud hide:YES]; }); // [hud hide:YES afterDelay:2.0]; }