Highly customizable replacement for UIAlertController/UIAlertView
- Includes content view property for adding custom views to the alert view
- Block-based API similar to UIAlertController/UIAlertAction
- Support for all screen orientations and iPad screen sizes
Add the files to your project manually by dragging the NYAlertViewController directory into your Xcode project.
Add pod 'NYAlertViewController'
to your Podfile, and run pod install
.
An example project is included in the NYAlertViewControllerDemo directory.
// Import the class and create an NYAlertViewController instance
#import "NYAlertViewController.h"
NYAlertViewController *alertViewController = [[NYAlertViewController alloc] initWithNibName:nil bundle:nil];
// Set a title and message
alertViewController.title = NSLocalizedString(@"Custom UI", nil);
alertViewController.message = NSLocalizedString(@"Integer posuere erat a ante venenatis dapibus posuere velit aliquet. Donec id elit non mi porta gravida at eget metus.", nil);
// Customize appearance as desired
alertViewController.buttonCornerRadius = 20.0f;
alertViewController.view.tintColor = self.view.tintColor;
alertViewController.titleFont = [UIFont fontWithName:@"AvenirNext-Bold" size:19.0f];
alertViewController.messageFont = [UIFont fontWithName:@"AvenirNext-Medium" size:16.0f];
alertViewController.buttonTitleFont = [UIFont fontWithName:@"AvenirNext-Regular" size:alertViewController.buttonTitleFont.pointSize];
alertViewController.cancelButtonTitleFont = [UIFont fontWithName:@"AvenirNext-Medium" size:alertViewController.cancelButtonTitleFont.pointSize];
// Add alert actions
[alertViewController addAction:[NYAlertAction actionWithTitle:NSLocalizedString(@"Done", nil)
style:UIAlertActionStyleCancel
handler:^(NYAlertAction *action) {
[self dismissViewControllerAnimated:YES completion:nil];
}]];
// Present the alert view controller
[self presentViewController:alertViewController animated:YES];
- Add different transition options (fade in, slide from top, etc.)
This project is released under the MIT License.