MDCAlertController

@interface MDCAlertController : UIViewController

MDCAlertController displays an alert message to the user, similar to UIAlertController.

https://material.io/go/design-dialogs

MDCAlertController class is intended to be used as-is and does not support subclassing. The view hierarchy for this class is private and must not be modified.

  • Convenience constructor to create and return a view controller for displaying an alert to the user.

    After creating the alert controller, add actions to the controller by calling -addAction.

    Note

    Most alerts don’t need titles. Use only for high-risk situations.

    Declaration

    Objective-C

    + (nonnull instancetype)alertControllerWithTitle:(nullable NSString *)title
                                             message:(nullable NSString *)message;

    Parameters

    title

    The title of the alert.

    message

    Descriptive text that summarizes a decision in a sentence of two.

    Return Value

    An initialized MDCAlertController object.

  • Alert controllers must be created with alertControllerWithTitle:message:

    Declaration

    Objective-C

    - (nonnull instancetype)initWithNibName:(nullable NSString *)nibNameOrNil
                                     bundle:(nullable NSBundle *)nibBundleOrNil;
  • Alert controllers must be created with alertControllerWithTitle:message:

    Declaration

    Objective-C

    - (nullable instancetype)initWithCoder:(nonnull NSCoder *)aDecoder;
  • The font applied to the title of Alert Controller.

    Declaration

    Objective-C

    @property (readwrite, strong, nonatomic, nullable) UIFont *titleFont;
  • The color applied to the title of Alert Controller.

    Declaration

    Objective-C

    @property (readwrite, strong, nonatomic, nullable) UIColor *titleColor;
  • The alignment applied to the title of the Alert Controller.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic) NSTextAlignment titleAlignment;
  • An optional icon appearing above the title of the Alert Controller.

    Declaration

    Objective-C

    @property (readwrite, strong, nonatomic, nullable) UIImage *titleIcon;
  • The tint color applied to the titleIcon. Leave empty to preserve original image color(s).

    Declaration

    Objective-C

    @property (readwrite, strong, nonatomic, nullable) UIColor *titleIconTintColor;
  • The font applied to the message of Alert Controller.

    Declaration

    Objective-C

    @property (readwrite, strong, nonatomic, nullable) UIFont *messageFont;
  • The color applied to the message of Alert Controller.

    Declaration

    Objective-C

    @property (readwrite, strong, nonatomic, nullable) UIColor *messageColor;
  • The font applied to the button of Alert Controller.

    Declaration

    Objective-C

    @property (readwrite, strong, nonatomic, nullable) UIFont *buttonFont;
  • The color applied to the button title text of Alert Controller.

    Declaration

    Objective-C

    @property (readwrite, strong, nonatomic, nullable) UIColor *buttonTitleColor;
  • The color applied to the button ink effect of Alert Controller.

    Declaration

    Objective-C

    @property (readwrite, strong, nonatomic, nullable) UIColor *buttonInkColor;
  • The semi-transparent color which is applied to the overlay covering the content behind the Alert (the scrim) when presented by MDCDialogPresentationController.

    Declaration

    Objective-C

    @property (readwrite, strong, nonatomic, nullable) UIColor *scrimColor;
  • The Alert’s background color.

    Declaration

    Objective-C

    @property (readwrite, strong, nonatomic, nullable) UIColor *backgroundColor;
  • The corner radius applied to the Alert Controller view. Default to 0 (no round corners)

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic) CGFloat cornerRadius;
  • The elevation that will be applied to the Alert Controller view. Default to 24.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic) MDCShadowElevation elevation;
  • High level description of the alert or decision being made.

    Use title only for high-risk situations, such as the potential loss of connectivity. If used, users should be able to understand the choices based on the title and button text alone.

    Declaration

    Objective-C

    @property (readwrite, copy, nonatomic, nullable) NSString *title;
  • Descriptive text that summarizes a decision in a sentence of two.

    Declaration

    Objective-C

    @property (readwrite, copy, nonatomic, nullable) NSString *message;
  • Undocumented

    Declaration

    Objective-C

    @property(nonatomic, readwrite, setter=mdc_setAdjustsFontForContentSizeCategory:)
        BOOL mdc_adjustsFontForContentSizeCategory
  • Affects the fallback behavior for when a scaled font is not provided.

    If @c YES, the font size will adjust even if a scaled font has not been provided for a given @c UIFont property on this component.

    If @c NO, the font size will only be adjusted if a scaled font has been provided.

    Default value is @c YES.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic)
        BOOL adjustsFontForContentSizeCategoryWhenScaledFontIsUnavailable;
  • MDCAlertController handles its own transitioning delegate.

    Declaration

    Objective-C

    - (void)setTransitioningDelegate:
        (id<UIViewControllerTransitioningDelegate> _Nullable)transitioningDelegate;
  • MDCAlertController.modalPresentationStyle is always UIModalPresentationCustom.

    Declaration

    Objective-C

    - (void)setModalPresentationStyle:
        (UIModalPresentationStyle)modalPresentationStyle;
  • The actions that the user can take in response to the alert.

    The order of the actions in the array matches the order in which they were added to the alert.

    Declaration

    Objective-C

    @property (readonly, nonatomic, nonnull) NSArray<MDCAlertAction *> *actions;
  • Adds an action to the alert dialog.

    Actions are the possible reactions of the user to the presented alert. Actions are added as a button at the bottom of the alert. Affirmative actions should be added before dismissive actions. Action buttons will be laid out from right to left if possible or top to bottom depending on space.

    Material spec recommends alerts should not have more than two actions.

    Declaration

    Objective-C

    - (void)addAction:(nonnull MDCAlertAction *)action;

    Parameters

    action

    Will be added to the end of MDCAlertController.actions.