An drop-in replacement for UIAlertController that looks a hell of a lot better, built in Objective-C. Based on Codedio's aweomse Swift library, PMAlertController.
Like PMAlertController, VSAlert builds on the functionality of UIAlertController by adding:
- Built-in support for images in the heading of the alert
- Much better animation
- Much more flexible customization, because alert actions are subclasses of UIButton.
VSAlertController differs from PMAlertController in a few ways:
- VSAlert doesn't build it's UI using a XIB file, which makes it a little bit more portable and easier to manage.
- VSAlert is written in Objective-C rather than Swift (but is marked up using nullability for easy use in Swift)
- VSAlert allows for a bit more customization at runtime.
- VSAlert adds the "destructive" action style from Apple's UIAlertController that was missing in PMAlertController
- VSAlert doesn't add actions and text fields in the order you create them, but rather in a dynamic order based on how many there are and what "style" they are (again, like Apple's UIAlertController)
- VSAlert doesn't rely on UITextFieldDelegate, so you can freely assign your UITextField's
.delegate
property without fear and the library will continue to work as expected. - VSAlert executes action blocks on the main-thread, to allow for UI actions and not get caught up by the main thread checker in Xcode 9.
- VSAlert adds the "Action Sheet" style from Apple's UIAlertController, missing from PMAlertController
- VSAlert uses propertransition, and respects the
animated
parameter in UIViewController's-presentViewController:animated:completion:
method
All you need are VSAlertController.h
, VSAlertController.m
, VSAlertAction.h
, and VSAlertAction.m
.
- Go to
(RepoDirectory)/Release/VSAlert.framework
, and add it to your project directory. - In your app target's settings, go to "General" --> "Linked Frameworks and Libraries", and add
VSAlert.framework
- In your target's build settings, go to "Other Linker Flags", and add
-all_load
and-ObjC
.
- Go to
(RepoDirectory)/VSAlert
, and add all the files excepting the modulemap and the umbrella header to your project. Make sure to add all the implementation files to your target'scompile sources
build phase, incase Xcode doesn't do this for you automatically when adding the files to the target's membership
The included Xcode project allows you to build the static library and an example application. Take a look at the example app to see all customization options, but here's a basic implementation:
#import "MyViewController.h"
@import VSAlert; // replace with #import 'VSAlertController.h' if you're using the source rather than the static framework
@implementation MyViewController
- (void)showAlert:(id)sender {
VSAlertController *alertController = [VSAlertController alertControllerWithTitle:NSLocalizedString(@"Alert!", nil) description:NSLocalizedString(@"This app needs your attention right now", nil) style:VSAlertControllerStyleAlert];
VSAlertAction *action = [VSAlertAction actionWithTitle:NSLocalizedString(@"Close", nil) style:VSAlertActionStyleDefault action:^(VSAlertAction *action) {
NSLog(@"Do Something");
}
[alertController addAction:action];
[self presentViewController:alertController animated:YES completion:nil];
}
@end
Full documentation is here, at https://code.vsanthanam.com/VSAlert/Documentation/index.html
Documentation with made with Jazzy by Realm, using the Jony Theme by Harshil Shah, and is hosted on GitHub Pages.
VSAlertController includes template images to help you size your images to make them look just right on an alert. I suggest using an Image that is 270pt tall and 180pt high, with your actual content centered in the middle at 116 x 116 pt. I've included PNGs with the appropriate outline, as well as a .sketch file