A-A+

高仿系统图原生UIAlertController

博客主机

支持

  • 高仿系统原生样式效果,有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];

示例图

  • gif 动画演示

Alert普通模式

Alert普通多Action模式

Alert带自定义Action模式

ActionSheet带自定义Action模式

给我留言

Copyright © ios教程,苹果粉丝,苹果资讯,ios入门教程,ios学习,ios程序员,ios视频教程,ios粉丝网 保留所有权利.   Theme  Ality

用户登录