Class
ModalDialog
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.
Relationships
Nested Types
ModalDialog.Style
The style of the modal dialog.
Conforms To
PanModalPresentable
UIViewController
Initializers
init(title:message:preferredStyle:)
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
Name | Type | Description |
---|---|---|
title | String? |
The title to show in the header. |
message | String? |
The message to show as the message body. |
preferredStyle | Style |
The style of the modal dialog. Defaults to .alert |
init(dateConfig:keyboardInputFieldTitle:keyboardInputFieldPlaceholder:didSelectDates:)
public init(
dateConfig: DatePickerConfiguration,
keyboardInputFieldTitle: String = "Enter Date",
keyboardInputFieldPlaceholder: String = "MM/DD/YYYY",
didSelectDates: @escaping ([Date]) -> Void
)
init(attributedTitle:attributedMessage:preferredStyle:)
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
Name | Type | Description |
---|---|---|
title | The title to show in the header. |
|
message | The message to show as the message body. |
|
preferredStyle | Style |
The style of the modal dialog. Defaults to .alert |
init(nibName: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
headerTextColor
public var headerTextColor: UIColor = ColorManager.shared.textBody
The color of the title text shown in the header.
headerBackgroundColor
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.
attributedTitle
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.
attributedMessage
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.
didTapClose
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.
tappableAttributeHandler
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
allowsTapToDismiss
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.
panScrollable
public var panScrollable: UIScrollView?
panModalBackgroundColor
public var panModalBackgroundColor: UIColor
showDragIndicator
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.
dateResult
public var dateResult: Date?
The Date that the user either selected or entered while using the DatePicker style
selectedDates
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.
preferredStatusBarStyle
override public var preferredStatusBarStyle: UIStatusBarStyle
Methods
make(title:message:preferredStyle:)
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
Name | Type | Description |
---|---|---|
title | String? |
The title to show in the header. |
message | String? |
The message to show as the message body. |
preferredStyle | Style |
The style of the modal dialog. Defaults to .alert |
makeDatePicker(config:keyboardInputFieldTitle:keyboardInputFieldPlaceholder:didSelectDates:)
public static func makeDatePicker(
config: DatePickerConfiguration,
keyboardInputFieldTitle: String = "Enter Date",
keyboardInputFieldPlaceholder: String = "MM/DD/YYYY",
didSelectDates: @escaping ([Date]) -> Void
) -> ModalDialog
make(attributedTitle:attributedMessage:preferredStyle:)
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
Name | Type | Description |
---|---|---|
title | The title to show in the header. |
|
message | The message to show as the message body. |
|
preferredStyle | Style |
The style of the modal dialog. Defaults to .alert |
viewDidLoad()
public override func viewDidLoad()
viewWillDisappear(_:)
public override func viewWillDisappear(_ animated: Bool)
addCheckbox(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.
addCheckbox(attributedText: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.
addTextField()
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.
addContentHeader(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.
addAction(_:)
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
Name | Type | Description |
---|---|---|
action | ModalDialogAction |
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. |