CreationKit Documentation

Class Modal​Dialog

public final class ModalDialog: UIViewController, PanModalPresentable  

Use this class to configure alerts with the message that you want to display and the actions from which to choose. After configuring the dialog with the actions and style you want, present it using the present(_:animated:, completion:) method. CreationKit displays dialogs modally over your app's content.

Prefer to use the make factory methods for initialization rather than the init constructors.

In addition to displaying a message to a user, you can associate actions with your dialog to give the user a way to respond. For each action you add using the addAction(_:) method, the controller configures a button with the action details. When the user taps that action, the controller executes the block you provided when creating the action object.

ModalDialog ModalDialog PanModalPresentable PanModalPresentable ModalDialog->PanModalPresentable UIViewController UIViewController ModalDialog->UIViewController

Nested Types

ModalDialog.Style

The style of the modal dialog.

Conforms To

PanModalPresentable
UIViewController

Initializers

init(title:​message:​preferred​Style:​)

public init(title: String?, message: String?, preferredStyle style: Style = .alert)  

Creates a new ModalDialog with a title and message.

Prefer to use the make factory method over this one.

Use addAction(_:) to insert action buttons.

Parameters

title String?

The title to show in the header.

message String?

The message to show as the message body.

preferred​Style Style

The style of the modal dialog. Defaults to .alert

init(date​Config:​keyboard​Input​Field​Title:​keyboard​Input​Field​Placeholder:​did​Select​Dates:​)

public init(
    dateConfig: DatePickerConfiguration,
    keyboardInputFieldTitle: String = "Enter Date",
    keyboardInputFieldPlaceholder: String = "MM/DD/YYYY",
    didSelectDates: @escaping ([Date]) -> Void
  )  

init(attributed​Title:​attributed​Message:​preferred​Style:​)

public init(
    attributedTitle: NSAttributedString?,
    attributedMessage: NSAttributedString?,
    preferredStyle style: Style = .alert
  )  

Creates a new ModalDialog with an attributed title and message.

Prefer to use the make factory method over this one.

Use addAction(_:) to insert action buttons.

Parameters

title

The title to show in the header.

message

The message to show as the message body.

preferred​Style Style

The style of the modal dialog. Defaults to .alert

init(nib​Name:​bundle:​)

@available(
  *,
  unavailable,
  message: "Please use `make(title:,message:)` or `init(attributedTitle:,attributedMessage:)` instead."
  )
  public override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?)  

Should NOT be used. Please use init(title:,message:) or init(attributedTitle:,attributedMessage:) instead.

Properties

header​Text​Color

public var headerTextColor: UIColor = ColorManager.shared.textBody  

The color of the title text shown in the header.

header​Background​Color

public var headerBackgroundColor: UIColor = .white  

The background color of the header.

title

public override var title: String?  

The title of the dialog.

The title string is displayed prominently in the dialog. You should use this string to get the user’s attention and communicate the reason for displaying the alert.

message

public var message: String?  

Descriptive text that provides more details about the reason for the alert.

The message string is displayed below the title string and is less prominent. Use this string to provide additional context about the reason for the alert or about the actions that the user might take.

attributed​Title

public var attributedTitle: NSAttributedString?  

The attributed title of the dialog.

The attributed title is displayed prominently in the dialog. You should use this attributed string to get the user’s attention and communicate the reason for displaying the alert.

attributed​Message

public var attributedMessage: NSAttributedString?  

Descriptive attributed text that provides more details about the reason for the alert.

The attributed message is displayed below the attributed title and is less prominent. Use this attributed string to provide additional context about the reason for the alert or about the actions that the user might take.

message​Font

public var messageFont: UIFont = FontManager.shared.subheading  

Message Font

data​Detector​Types

public var dataDetectorTypes: UIDataDetectorTypes = []  

Data Detectors

did​Tap​Close

public lazy var didTapClose: (() -> Void)  

Called when the user taps the close button at the top right.

By default, this will just dismiss the dialog. You can use this to intercept the closure if need be.

tappable​Attribute​Handler

public lazy var tappableAttributeHandler: (String) -> Void  

Called when any attributed text that is attributed with NSAttributedString.Key.tappable is tapped.

Can be overridden to handle any attributed text that is attributed with NSAttributedString.Key.tappable

allows​Tap​ToDismiss

public var allowsTapToDismiss: Bool = false

Set to true to allow the user to dismiss the modal by tapping outside of the view. Defaults to false. Will automatically become true if you provide a cancel action.

pan​Scrollable

public var panScrollable: UIScrollView?  

pan​Modal​Background​Color

public var panModalBackgroundColor: UIColor  

show​Drag​Indicator

public var showDragIndicator: Bool  

Enabling this property will display a drag indicator outside of the presented modal window, managed by PanModal. Since our requirements specify an internal drag indicator, we set this to false and create our own on the modal header.

date​Result

public var dateResult: Date?  

The Date that the user either selected or entered while using the DatePicker style

selected​Dates

public private(set) var selectedDates: [Date]? = nil  

Used to store the selected date when the DatePicker style is used with ranged selection enabled. When ranged selection is disabled, selectedDate is used instead.

preferred​Status​Bar​Style

override public var preferredStatusBarStyle: UIStatusBarStyle  

Methods

make(title:​message:​preferred​Style:​)

public static func make(
    title: String?,
    message: String?,
    preferredStyle style: Style = .alert
  ) -> ModalDialog  

Creates a new ModalDialog with a title and message.

Use addAction(_:) to insert action buttons.

Parameters

title String?

The title to show in the header.

message String?

The message to show as the message body.

preferred​Style Style

The style of the modal dialog. Defaults to .alert

make​Date​Picker(config:​keyboard​Input​Field​Title:​keyboard​Input​Field​Placeholder:​did​Select​Dates:​)

public static func makeDatePicker(
    config: DatePickerConfiguration,
    keyboardInputFieldTitle: String = "Enter Date",
    keyboardInputFieldPlaceholder: String = "MM/DD/YYYY",
    didSelectDates: @escaping ([Date]) -> Void
  ) -> ModalDialog  

make(attributed​Title:​attributed​Message:​preferred​Style:​)

public static func make(
    attributedTitle: NSAttributedString?,
    attributedMessage: NSAttributedString?,
    preferredStyle style: Style = .alert
  ) -> ModalDialog  

Creates a new ModalDialog with an attributed title and message.

Use addAction(_:) to insert action buttons.

Parameters

title

The title to show in the header.

message

The message to show as the message body.

preferred​Style Style

The style of the modal dialog. Defaults to .alert

view​Did​Load()

public override func viewDidLoad()  

view​Will​Disappear(_:​)

public override func viewWillDisappear(_ animated: Bool)  

add​Checkbox(text:​multiline:​)

public func addCheckbox(text: String, multiline: Bool = false) -> Component<CheckboxActionLayout>  

Call this to add a checkbox to the modal. This will display the checkbox under any message that may be set, and above any actions that may be set.

Returns

Component<CheckboxActionLayout> - You can use this to manage the checkbox.

add​Checkbox(attributed​Text:​multiline:​alignment:​)

public func addCheckbox(attributedText: NSAttributedString, multiline: Bool = false, alignment: UIStackView.Alignment? = nil) -> Component<CheckboxActionLayout>  

Call this to add a checkbox with attributed text to the modal. This will display the checkbox under any message that may be set, and above any actions that may be set. Set the multiline and alignment arguments depending on your layout needs.

Returns

Component<CheckboxActionLayout> - You can use this to manage the checkbox.

add​Text​Field()

public func addTextField() -> Component<TextInputFormLayout>  

Call this to add a text field to the modal. This will display the text field under any message that may be set, and above any actions that may be set.

Returns

Component<TextInputFormLayout> - You can use this to manage the text field.

add​Content​Header(view:​)

public func addContentHeader(view: UIView)  

Call this to add any view you'd like to display above the message content. You should set the height anchor to the size this should be.

add​Action(_:​)

func addAction(_ action: ModalDialogAction)  

Attaches an action object to the dialog.

If your alert has multiple actions, the order in which you add those actions determines their order in the resulting dialog, with some exceptions. Actions with the .cancel style will always be positioned to the left side when displayed in an alert, and at the bottom when displayed in an actionSheet.

If three or more actions are needed, ensure you set the ModalDialog to use the .actionSheet style. It is a programmer error to add more than 2 actions to an alert.

Parameters

action Modal​Dialog​Action

The action object to display as part of the dialog. Actions are displayed as buttons in the dialog. The action object provides the button text and the action to be performed when that button is tapped.