CYAlertController 1.0.3

CYAlertController 1.0.3

TestsTested
LangLanguage Obj-CObjective C
License MIT
ReleasedLast Release Oct 2016

Maintained by Cyrus.



  • By
  • hcy91425

2016.10.30 更新

  1. 修复了在屏幕旋转时灰色半透明背景没有约束的bug。
  2. 最近工作比较忙,自己也升入大四了,还要准备毕设和毕业的事情,太久没有更新自己的Github了。目前只能简单的修复一下小bug,有空的时候准备一波大更新,敬请期待🤔

CYAlertController


一个初学者的第一次尝试。喜欢的,支持的,欢迎 star⭐️,fork。没有很多经验,很多东西都是自己的思路,如果有不对的地方希望大家能够指出。

高仿官方 Alert 外观,提供多种自定义的转场动画,以及相似的 API。

外观&动画


支持多个button,自适应高度

部分动画

使用


导入

pod 'CYAlertController'

也可以直接往项目中拖入 CYAlertController 文件夹到你的项目中

然后在需要使用的地方导入头文件

#import "CYAlertController.h"

调用

CYAlertController 提供了几乎与官方一样的API:

CYAlertController *alert = [CYAlertController alertWithTitle:@"警告!警告!💥"
                                                     message:@"逗你玩儿呢 ~ 😜"];
alert.presentStyle = CYAlertPresentStyleSystem;
alert.dismissStyle = CYAlertDismissStyleFadeOut;

// 或者直接一口气初始化
CYAlertController *alert2 = [CYAlertController alertWithTitle:@"警告!警告!💥"
                                                      message:@"逗你玩儿呢 ~ 😜"
                                                 presentStyle:CYAlertPresentStyleSystem
                                                 dismissStyle:CYAlertDismissStyleFadeOut];

// 还可以设置 alertView 的圆角半径,默认为6
alert.alertViewCornerRadius = 10;

创建 action(提供了3中与官方一样的style),给 alert 添加 action :

CYAlertAction *defaultAction = [CYAlertAction actionWithTitle:@"确定" style:CYAlertActionStyleDefault handler:^{ NSLog(@"Default"); }];
CYAlertAction *destructiveAction = [CYAlertAction actionWithTitle:@"危险" style:CYAlertActionStyleDestructive handler:^{ NSLog(@"Destructive"); }];
CYAlertAction *cancelAction = [CYAlertAction actionWithTitle:@"取消" style:CYAlertActionStyleCancel handler:^{ NSLog(@"Cancel"); }];

// 一次性添加
[alert addActions:@[defaultAction, destructiveAction, cancelAction]];

// 也可以一个个添加
[alert addAction:defaultAction];
[alert addAction:destructiveAction];
[alert addAction:cancelAction];

最后就直接 present:

[self presentViewController:alert animated:YES completion:nil];

转场的动画

目前提供了9种present动画,7种dismiss动画

// present style
typedef NS_ENUM(NSInteger, CYAlertPresentStyle) {
    CYAlertPresentStyleSystem,          // 系统样式
    CYAlertPresentStyleFadeIn,          // 渐入
    CYAlertPresentStyleBounce,          // 弹出
    CYAlertPresentStyleExpandHorizontal,// 水平展开
    CYAlertPresentStyleExpandVertical,  // 垂直展开
    CYAlertPresentStyleSlideDown,       // 从上往下划入
    CYAlertPresentStyleSlideUp,         // 从下往上划入
    CYAlertPresentStyleSlideLeft,       // 从右往左划入
    CYAlertPresentStyleSlideRight,      // 从左往右划入
};

// dismiss style
typedef NS_ENUM(NSInteger, CYAlertDismissStyle) {
    CYAlertDismissStyleFadeOut,             // 渐出
    CYAlertDismissStyleContractHorizontal,  // 水平收起
    CYAlertDismissStyleContractVertical,    // 垂直收起
    CYAlertDismissStyleSlideDown,           // 向下划出
    CYAlertDismissStyleSlideUp,             // 向上划出
    CYAlertDismissStyleSlideLeft,           // 向左划出
    CYAlertDismissStyleSlideRight,          // 向右划出
};

更多细节可以直接看demo~

计划


  • 加入更多的转场动画
  • 支持自定义动画
  • 提供更多种类的alert,如 ActionSheet

联系我


微博 @Cyrus_dev