|
1 | 1 | # RKOTopAlert
|
2 | 2 |
|
3 | 3 | <p align="center">
|
4 |
| -<a href=""><img src="https://img.shields.io/badge/pod-v1.0.2-brightgreen.svg"></a> |
| 4 | +<a href=""><img src="https://img.shields.io/badge/pod-v1.0.3-brightgreen.svg"></a> |
5 | 5 | <a href=""><img src="https://img.shields.io/badge/ObjectiveC-compatible-orange.svg"></a>
|
6 | 6 | <a href=""><img src="https://img.shields.io/badge/platform-iOS%207.0%2B-ff69b5152950834.svg"></a>
|
7 | 7 | <a href="https://github.com/rakuyoMo/RKOTools/blob/master/LICENSE"><img src="https://img.shields.io/badge/license-MIT-green.svg?style=flat"></a>
|
|
11 | 11 |
|
12 | 12 | 自定义一个顶端的`Alert`提示窗。弹出时从顶端向下移动。(**在iPhone X下可用**)
|
13 | 13 |
|
| 14 | +随仓库配套了一个简单的 **演示Demo**,方便大家使用参考。 |
| 15 | + |
14 | 16 | 可以设置**提示文字**、**文字颜色**、**背景颜色**。
|
15 | 17 |
|
16 | 18 | **高度**为`Status` + `NavigationBar`的高度。(不论您的`ViewController`是否添加到`NavigationController`中)
|
|
30 | 32 | ## 集成
|
31 | 33 |
|
32 | 34 | ```shell
|
33 |
| - pod 'RKOTopAlert', '~> 1.0.2' |
| 35 | + pod 'RKOTopAlert', '~> 1.0.3' |
34 | 36 | ```
|
35 | 37 |
|
36 | 38 | ## 使用
|
37 | 39 |
|
38 |
| -在需要弹出该提示窗的地方调用下面的方法: |
| 40 | +使用下面的方法创建一个`Alert`视图,对`Alert`视图调用 `alertAppearWithDuration` 并设置时候,即可弹出 `Alert`视图。 |
39 | 41 |
|
40 | 42 | ```objc
|
41 |
| -[RKOTopAlert popAlertViewWithText:@"提醒文字" textColor:[UIColor whiteColor] ackgroundColor:[UIColor redColor]; |
| 43 | +RKOTopAlert *topAlert = [RKOTopAlert alertViewWithText:@"提示文字" textColor:[UIColor whiteColor] ackgroundColor:[UIColor redColor]]; |
| 44 | + |
| 45 | +[topAlert alertAppearWithDuration:2.0]; |
42 | 46 | ```
|
43 | 47 |
|
44 |
| -如果您的`App`需要统一多个提示窗的样式,那么推荐您使用下面的方法: |
| 48 | +如果您的`App`需要统一多个提示窗的样式,那么推荐您在 `AppDelegate` 中进行设置: |
45 | 49 |
|
46 | 50 | ```objc
|
47 |
| -// 创建单例并设置样式。 |
48 |
| -RKOTopAlert *topAlert = [[self sharedManager] alertViewWithText:@"提醒文字" textColor:[UIColor whiteColor] ackgroundColor:[UIColor redColor]]; |
49 |
| - |
50 |
| -// 出现 |
51 |
| -[topAlert alertAppearWithDuration:0.3f]; |
| 51 | +// 在 AppDelegate.h 中设置属性 |
| 52 | +@property (nonatomic, strong) RKOTopAlert *topAlert; |
| 53 | +
|
| 54 | +// 懒加载属性,创建对象并设置样式。 |
| 55 | +- (RKOTopAlert *)topAlert { |
| 56 | + return [RKOTopAlert alertViewWithText:@"在AppDelegate中总体设置" textColor:[UIColor blackColor] ackgroundColor:[UIColor orangeColor]]; |
| 57 | +} |
| 58 | +
|
| 59 | +// 在按钮方法或其它方法中,获取属性调用弹出方法。 |
| 60 | +- (IBAction)popAlert:(id)sender { |
| 61 | + [((AppDelegate *)[UIApplication sharedApplication].delegate).topAlert alertAppearWithDuration:2.0]; |
| 62 | +} |
52 | 63 | ```
|
53 | 64 |
|
54 | 65 | ## 接口
|
55 | 66 |
|
56 |
| -该提示窗提供一个方法用于设置样式并弹出提示窗。 |
| 67 | +本控件提供一个工厂方法,用以创建对象并设置样式: |
57 | 68 |
|
58 | 69 | ```objc
|
59 | 70 | /**
|
60 | 71 | * 设置提示窗的样式,并弹出提示窗。(其对象参数均不可为nil。)
|
61 |
| -
|
62 |
| - * @param text 提示窗显示文字。 |
63 |
| - * @param textColor 文字颜色。 |
64 |
| - * @param backgroundColor 提示窗背景颜色。 |
65 |
| - * @param duration 横幅持续显示的时间。 |
66 |
| - */ |
67 |
| -+ (void)popAlertViewWithText:(NSString *)text |
68 |
| - textColor:(UIColor *)textColor |
69 |
| - ackgroundColor:(UIColor *)backgroundColor |
70 |
| - duration:(CGFloat)duration; |
71 |
| -``` |
72 |
| - |
73 |
| -此外,考虑到您可以需要统一的设置多个弹窗,我们提供如下的方法进行设置: |
74 |
| - |
75 |
| -```objc |
76 |
| -/** |
77 |
| - * 单例方法,创建对象。 |
78 |
| -
|
79 |
| - * @return 提示窗Alert。 |
80 |
| - */ |
81 |
| -+ (RKOTopAlert *)sharedManager; |
82 |
| - |
83 |
| -/** |
84 |
| - * 设置样式。(其对象参数均不可为nil。) |
85 |
| -
|
| 72 | + |
86 | 73 | * @param text 提示窗显示文字。
|
87 | 74 | * @param textColor 文字颜色。
|
88 | 75 | * @param backgroundColor 提示窗背景颜色。
|
| 76 | + * @return 调用对象本身 |
89 | 77 | */
|
90 |
| -- (void)alertViewWithText:(NSString *)text |
91 |
| - textColor:(UIColor *)textColor |
92 |
| - ackgroundColor:(UIColor *)backgroundColor; |
| 78 | ++ (instancetype)alertViewWithText:(NSString *)text |
| 79 | + textColor:(UIColor *)textColor |
| 80 | + ackgroundColor:(UIColor *)backgroundColor; |
93 | 81 | ```
|
94 | 82 |
|
95 |
| -此外,我们分别提供了弹窗弹窗的**弹出**方法与**消失**方法,方便您在他处动态地控制弹窗的弹出与消失: |
| 83 | +此外,我们分别提供了弹窗弹窗的**弹出**方法与**消失**方法,方便您动态地控制弹窗的弹出与消失: |
96 | 84 |
|
97 | 85 | ```objc
|
98 | 86 | /**
|
99 | 87 | * 弹出提示窗的方法。
|
100 | 88 |
|
101 |
| - * @param duration 横幅持续显示的时间。 |
| 89 | + * @param duration 横幅持续显示的时间。如果传0,则需要手动调用alertDisappear方法使视图消失。 |
102 | 90 | */
|
103 | 91 | - (void)alertAppearWithDuration:(CGFloat)duration;
|
104 | 92 |
|
|
0 commit comments