美文网首页
高仿系统图原生UIAlertController

高仿系统图原生UIAlertController

作者: Gxdy | 来源:发表于2020-03-17 13:42 被阅读0次

支持

  • 高仿系统原生样式效果,有Alert和Sheet两种模式
  • 支持自定义文本字体和颜色
  • 支持自定义view作为Action
  • 支持横屏
  • 支持深色模式
  • 不支持文本输入,但可以采用自定义view作为Action的方式实现
  • 只支持iOS 9.0及以上系统
  • 支持pod

用法

  • 与UIAlertController的用法高度一致
  • demo下载
  • 直接将demo中TLAlertLib文件夹中的文件导入到项目即可使用
  • 也可以pod
    'TLAlertLib', '~> 1.0.0'
  • 示例代码
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普通模式
2.jpg
  • Alert普通多Action模式
1.jpg
  • Alert带自定义Action模式
3.jpg
  • ActionSheet带自定义Action模式
4.jpg

相关文章

网友评论

      本文标题:高仿系统图原生UIAlertController

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