TLAlertController
类似 UIAlertController
常见问题解答
- 在进行
dismiss/pop
转场后立即使用 TLAlertController 显示弹窗时显示失败或坐标不对
- 导致该问题的原因是
dismiss/pop
转场事件尚未完全结束。因为同一时间只能有一个转场事务,所以只要在转场事件完全结束后再发起弹窗即可(例如,在dismiss/pop
转场完成回调中发起弹窗)
支持
- 高度仿制系统原生样式效果,有 Alert 和 Sheet 两种模式
- 支持自定义文本字体和颜色等
- 支持 title 和 message 富文本(1.1.1)
- 组件行高、宽度、message 文本对齐等样式设置(1.1.1)
- 支持自定义 view 作为 Action
- 支持横屏
- 支持深色模式
- 不支持文本输入,但可以通过自定义 view 作为 Action 的方式实现
- 只支持 iOS 9.0 及以上系统
- 支持 pod
用法
- 与 UIAlertController 的用法高度一致
- 直接将 demo 中
Lib 文件夹中的文件
导入到项目即可使用 - 也可以 pod
'TLAlertLib', '~> 1.1.1'
- 示例代码
TLAlertController *alertController = [TLAlertController alertControllerWithTitle:@"故乡的云" message:@"Copyright © 2020 故乡的云. All rights reserved" preferredStyle:TLAlertControllerStyleActionSheet];
[alertController addAction:[TLAlertAction actionWithTitle:@"Action (Enabel = NO)" style:TLAlertActionStyleDefault handler:^(TLAlertAction * _Nonnull action) {
NSLog(@"%@", action.title);
}]];
[alertController addAction:[TLAlertAction actionWithTitle:@"Action2 (Default)" style:TLAlertActionStyleDefault handler:^(TLAlertAction * _Nonnull action) {
NSLog(@"%@", action.title);
}]];
[alertController addAction:[TLAlertAction actionWithTitle:@"Action3 (Destructive)" style:TLAlertActionStyleDestructive handler:^(TLAlertAction * _Nonnull action) {
NSLog(@"%@", action.title);
}]];
/// 用自定义view作为Action
UIView *redView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bg"]];
redView.userInteractionEnabled = YES;
[alertController addAction:[TLAlertAction actionWithCustomView:redView style:TLAlertActionStyleDestructive handler:^(TLAlertAction * _Nonnull action) {
NSLog(@"CustomView");
}]];
[alertController addAction:[TLAlertAction actionWithTitle:@"Cancel" style:TLAlertActionStyleCancel handler:nil]];
[alertController showInViewController:self];
示例图
- Alert 普通模式
- Alert 多 Action 普通模式
- Alert 带自定义 Action 模式
- ActionSheet 带自定义 Action 模式