VSAlertController
@interface VSAlertController : UIViewController <UIAppearance>
VSAlertController is a drop-in replacement for UIAlertController with more features. It is created using the +alertControllerWithTitle:message:image:style:
class method, and configured using instances of VSAlertAction. You can add text fields by calling -addTextField:
on an instance of VSAlertController. Instantiate the controller, add your actions and textfieds. and any other configuration you might need. Present the controller modally using UIViewController’s -presentViewController:animated:completion:
method. VSAlertController respects the animation paramater of this call, and you configure the animation in question by setting your instances animationStyle property before presentation. You can also change this property in the handler of an action to use a different animation on dismissal.
-
A factory method to create an instance of VSAlertController. This is the preffered way to instantiate alerts
Declaration
Objective-C
+ (nullable instancetype)alertControllerWithTitle:(nullable NSString *)title message:(nullable NSString *)message image:(nullable UIImage *)image preferredStyle: (VSAlertControllerStyle)preferredStyle;
Parameters
title
The title of the alert
message
The message of the alert
image
The image to be displayed in the header of the alert.
preferredStyle
The style of the alert
Return Value
The instantiated alert object
-
A factory method to create an instance of VSAlertController.
Declaration
Objective-C
+ (nullable instancetype)alertControllerWithTitle:(nullable NSString *)title message:(nullable NSString *)message preferredStyle: (VSAlertControllerStyle)preferredStyle;
Parameters
title
The title of the alert
message
The message of the alert
preferredStyle
The style of the alert
Return Value
The instantiated alert object
-
Create an instance of VSAlertController
Declaration
Objective-C
- (nullable instancetype)initWithTitle:(nullable NSString *)title message:(nullable NSString *)message image:(nullable UIImage *)image preferredStyle:(VSAlertControllerStyle)preferredStyle;
Parameters
title
The title of the alert
message
The message of the alert
image
The image to be displayed in the header of the alert.
preferredStyle
The style of the alert
Return Value
The instantiated alert object
-
The color of the alert title. The default value is black.
Declaration
Objective-C
@property (readwrite, strong, nonatomic, nonnull) UIColor *alertTitleTextColor;
-
The color of the alert message (description). The default value is black.
Declaration
Objective-C
@property (readwrite, strong, nonatomic, nonnull) UIColor *alertMessageTextColor;
-
The font of the alert title. The default value is the system font size 17 weight medium.
Declaration
Objective-C
@property (readwrite, strong, nonatomic, nonnull) UIFont *alertTitleTextFont;
-
The font of the alert message (description). The default value is the system font size 15 weight regular.
Declaration
Objective-C
@property (readwrite, strong, nonatomic, nonnull) UIFont *alertMessageTextFont;
-
The text alignment of the alert message
Declaration
Objective-C
@property (assign, readwrite, nonatomic) NSTextAlignment alertMessageTextAlignment;
-
The background color of the alert
Declaration
Objective-C
@property (readwrite, strong, nonatomic, nonnull) UIColor *alertBackgroundColor;
-
Add an action to an alert
Declaration
Objective-C
- (void)addAction:(nonnull VSAlertAction *)alertAction;
Parameters
alertAction
The action to add to the alert.
-
Add a text field to the alert. Rather than instantiating a UITextField object yourself, VSAlertController instantiates one for you. You can configure it using the optional configuration block
Declaration
Objective-C
- (void)addTextField:(void (^_Nullable)(UITextField *_Nonnull))configuration;
Parameters
configuration
The block used to configure the text field.
-
Set to YES if you want the alert to dismiss itself when the user taps on the background of the alert. Default is NO.
Declaration
Objective-C
@property (getter=shouldDismissOnBackgroundTap, assign, readwrite, nonatomic) BOOL dismissOnBackgroundTap;
-
Change the animation used when the alert is presented AND dismissed. Default is VSAlertControllerAnimationStyleRise.
Declaration
Objective-C
@property (assign, readwrite, nonatomic) VSAlertControllerAnimationStyle animationStyle;
-
The delegate object to handle alert action interactions
Declaration
Objective-C
@property (readwrite, atomic, nullable) id<VSAlertControllerDelegate> delegate;
-
Returns the array of text field objects that are displayed in the alert, so you can interact with the user’s inputs.
Declaration
Objective-C
@property (readonly, strong, nonatomic, nonnull) NSArray<UITextField *> *textFields;
-
The style of the alert
Declaration
Objective-C
@property (readonly, assign, nonatomic) VSAlertControllerStyle style;
-
The message of the alert
Declaration
Objective-C
@property (readonly, copy, nonatomic, nonnull) NSString *message;
-
The image of the alert
Declaration
Objective-C
@property (readonly, strong, nonatomic, nullable) UIImage *image;