CocoaPods trunk is moving to be read-only. Read more on the blog, there are 19 months to go.
TestsTested | ✗ |
LangLanguage | Obj-CObjective C |
License | MIT |
ReleasedLast Release | Dec 2014 |
Maintained by Roland Tecson.
UIAlertView replacement for iOS 7 and iOS 6
RTAlertView is a customizable alert view that looks identical to the iOS 7 system alert view. It implements the same interface as UIAlertView, but it also allows you to customize the fonts and colours used in the alert view.
The alert uses auto layout to position itself in the center of the screen, and will automatically adjust its position when the device orientation changes, or when the keyboard is displayed.
The following properties, in addition to those defined for UIAlertView, are defined in RTAlertView:
@property (strong, nonatomic) UIColor *titleColor;
@property (strong, nonatomic) UIFont *titleFont;
@property (strong, nonatomic) UIColor *messageColor;
@property (strong, nonatomic) UIFont *messageFont;
@property (strong, nonatomic) UIColor *cancelButtonColor;
@property (strong, nonatomic) UIFont *cancelButtonFont;
@property (strong, nonatomic) UIColor *otherButtonColor;
@property (strong, nonatomic) UIFont *otherButtonFont;
@property (strong, nonatomic) UIFont *textFieldPlaceholderFont;
If no values are specified for these properties, the default colours and fonts used will be the same as the ones in UIAlertView.
The highlight colour of a button is automatically derived from the button's colour.
Similarly to UIAlertView, if two buttons are defined, they are laid out side by side.
If three or more buttons are defined, they are laid out vertically.
Similarly to UIAlertView, if alertViewStyle
were set to either UIAlertViewStyleSecureTextInput
or UIAlertViewStylePlainTextInput
, a single text field will be displayed.
If alertViewStyle
were set to UIAlertViewStyleLoginAndPasswordInput
, two text fields will be displayed.
By default, RTAlertView will automatically dismiss itself when the app goes to the background. This is as per Apple's recommendation so that the user will not be presented with an alert message that may be out of context when the app is resumed. You may override this behaviour by setting the property dismissesWhenAppGoesToBackground
to NO
(default value is YES
).
RTAlertView dims the tintColor of the all the visible controls in your app (at least those that support it), similar to the iOS 7 UIAlertView. RTAlertView also implements the parallax effect present in the iOS 7 UIAlertView.
Swift does not support direct bridging to Objective C variable arguments methods. Unfortunately, the designated initializer for UIAlertView (and hence RTAlertView as it tries to mirror UIAlertView's public API) is a variable arguments method.
- (id)initWithTitle:(NSString *)title
message:(NSString *)message
delegate:(id)delegate
cancelButtonTitle:(NSString *)cancelButtonTitle
otherButtonTitles:(NSString *)otherButtonTitles, ...;
To get around this, a secondary initializer is provided by RTAlertView that takes a fixed number of parameters. This initializer only takes one otherButtonTitle
(which may be nil if one does not exist). If additional other button titles are required, the method -addButtonTitle:
may be used.
- (id)initWithTitle:(NSString *)title
message:(NSString *)message
delegate:(id)delegate
cancelButtonTitle:(NSString *)cancelButtonTitle
otherButtonTitle:(NSString *)otherButtonTitle;
For use in your app, install with Cocoapods
Podfile
and add the following line pod 'RTAlertView', '0.0.6'
pod install
#import <RTAlertView.h>
to your class<App>.xcworkspace
file (not <App>.xcodeproj
) in Xcode from here onwardsTo run the test application
git clone https://github.com/rtecson/RTAlertView.git
cd RTAlertView
pod install
(if cocoapods is not installed, see http://http://beta.cocoapods.org)RTAlertView.xcworkspace
// Alloc and init RTAlertView, button titles may also be set here
RTAlertView *customAlertView = [[RTAlertView alloc] initWithTitle:@"Test"
message:@"Message here"
delegate:nil
cancelButtonTitle:nil
otherButtonTitles:nil];
// Conforms to the RTAlertViewDelegate protocol
customAlertView.delegate = self;
// Default is UIAlertViewStyleDefault
customAlertView.alertViewStyle = UIAlertViewStylePlainTextInput;
// Add other buttons
for (int i=0; i<kNumberOfOtherButtons; i++)
{
[customAlertView addButtonWithTitle:[NSString stringWithFormat:@"Button %d", i]];
}
// Add cancel button
customAlertView.cancelButtonIndex = [customAlertView addButtonWithTitle:@"Done"];
// Set button colours
customAlertView.otherButtonColor = kCustomColor;
customAlertView.cancelButtonColor = kCustomColor;
// Display alert view
[customAlertView show];
RTAlertView is written by Roland Tecson. It is licensed under the MIT License.
If you use RTAlertView in one of your apps, please send me a quick note. I'd love to hear about it.