Features:
- 和 UIAlertController 使用相同的 API;
- 自帶
-show和-dismiss, 不需要考慮從哪個 view controller present 的問題; - 自動忽略長度為 0 的 title, 不會在 iOS 8 出現一個難看的空 title.
Known issues:
- text field 在 iOS 7 和 iOS 8 的差別太大, 無法同時支持;
- controller 繼承自
NSObject, 無法當做普通的 view controller 使用 (下個版本修改).
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:
- sending me iTunes Gift Cards;
- via Alipay: [email protected]
- via PayPal: [email protected]
:-)
