兼容 iOS 7 的 Alert Controller

2014-11-01 14:11:27 +08:00
 Elethom

Features:

Known issues:

https://github.com/Elethom/PRAlertController

PRAlertController

Alert controller with the same APIs as iOS 8 SDK (text field not supported), compatible with iOS 7.

Installation

With CocoaPods

In your Podfile:

pod 'PRAlertController'

Usage

It has exactly the same APIs as iOS 8 SDK does except the text field part. Besides, with -show, -dismiss methods you can pop up alerts wherever you want without having to worry about how to get current view controller's pointer.

Example:

PRAlertController *alertController = [PRAlertController alertControllerWithTitle:@"Title"
                                                                         message:@"This is the message."
                                                                  preferredStyle:PRAlertControllerStyleAlert];
PRAlertAction *firstAction = [PRAlertAction actionWithTitle:@"First"
                                                      style:PRAlertActionStyleDefault
                                                    handler:^(PRAlertAction *action) {
                                                        [self doFirstAction];
                                                    }];
PRAlertAction *secondAction = [PRAlertAction actionWithTitle:@"Second"
                                                       style:PRAlertActionStyleDefault
                                                     handler:^(PRAlertAction *action) {
                                                         [self doSecondAction];
                                                     }];
PRAlertAction *destructiveAction = [PRAlertAction actionWithTitle:@"Destructive"
                                                            style:PRAlertActionStyleDestructive
                                                          handler:^(PRAlertAction *action) {
                                                              [self doDestructiveAction];
                                                          }];
PRAlertAction *cancelAction = [PRAlertAction actionWithTitle:@"Cancel"
                                                       style:PRAlertActionStyleCancel
                                                     handler:^(PRAlertAction *action) {
                                                         [self doCancelAction];
                                                     }];
[alertController addAction:firstAction];
[alertController addAction:secondAction];
[alertController addAction:destructiveAction];
[alertController addAction:cancelAction];
[alertcontroller show];

Easy as it seems.

License

This code is distributed under the terms and conditions of the MIT license.

Donate

You can support me by:

:-)

Contact

3530 次点击
所在节点    iDev
13 条回复
yellowV2ex
2014-11-01 16:43:09 +08:00
输入帐号密码或文本的那种alert怎么写?
xhacker
2014-11-01 16:54:38 +08:00
@Livid: 在 iOS 上代码的字体有问题。
Elethom
2014-11-03 16:22:54 +08:00
@xhacker
Mac 上也有問題.
Elethom
2014-11-03 16:25:40 +08:00
@xhacker
@Livid
Fallback 中的字體我一個都沒有...
Livid
2014-11-03 16:29:16 +08:00
@xhacker
@Elethom

收到,我现在调整。
Elethom
2014-11-03 16:31:46 +08:00
@Livid
建議調整為可左右滾動的, 折行很難看.
Livid
2014-11-03 16:31:47 +08:00
@xhacker
@Elethom

现在加入了 Menlo
Elethom
2014-11-03 16:37:49 +08:00
@Livid
搜索了一下, 原來 Panic Sans 是 Coda 附帶的字體, 難怪叫做 "Panic". XD
Livid
2014-11-03 16:44:24 +08:00
@Elethom 个人最爱的代码字体。
Elethom
2014-11-03 16:50:46 +08:00
@Livid

似乎沒有單獨的下載?

試了一下, 給代碼部份的 CSS 加上:
white-space: pre;
overflow-x: scroll;
這樣比較好, 可以橫向滾動, 換行不好看.
Livid
2014-11-03 16:52:33 +08:00
@Elethom 好的,现在调整。
Esay
2014-11-03 17:06:29 +08:00
酷,给你补个截图(代码最后一行的 Controller 大小写写错了)

Elethom
2014-11-03 17:44:35 +08:00
@Livid
似乎還沒 update?

@Esay
Thanks! 已修改.

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/143168

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX