FUIToastMessage

public class FUIToastMessage

FUIToastMessage provides convenience class methods for showing an overlay toast-type message centered on screen. Only one message can be visible at the same time and the FUIToastMessage class makes sure that previous messages are properly dismissed before the next is shown.

You use the show() method to display messages. By default, the toast message is shown for one second but applications can change that duration.

Note

A toast message is meant to be used for short messages and is limited to one line of text by default. This can be changed by applications by setting the maxNumberOfLines parameter to another value.

Usage

Show Fullscreen

FUIToastMessage.show(message: This is a message)

Show Fullscreen with Custom Duration

FUIToastMessage.show(message: This is a message, withDuration: 3)

  • Shows the toast message in the center of the screen with a given duration. This method dispatches all UIKit drawing back to the main thread, so it is safe to call it from a background thread.

    • Parameters:

    Only one message can be visible at the same time. If show(message: String) is called while another message is visible the first one is dismissed.

    Declaration

    Swift

    public class func show(message: String, icon: UIImage = FUIToastMessageView.checkmarkImage, inWindow window: UIWindow = FUIToastMessageView.keyWindow, withDuration duration: Float = 1.0, maxNumberOfLines lines: Int = 1)

    Parameters

    parameter message

    the text of the toast message.

    parameter icon

    the icon in front of the text. The default is a checkmark icon.

    parameter inWindow

    the Window in which the toast message is displayed. This defaults to the application’s key window.

    parameter duration

    the duration in seconds for which the toast message is shown. The default is 1.

    parameter lines

    maximum number of lines the text message can have. The default is 1. A value of 0 does not restrict the number of lines at all.

  • Shows the toast message in the center of the given container view with a given duration. This method dispatches all UIKit drawing back to the main thread, so it is safe to call it from a background thread.

    • Parameters:
      • message: the text of the toast message.
      • icon: the icon in front of the text. The default is a checkmark icon.
      • inView: the container view in which to display the toast message. The toast message will be shown centered in the container.
      • duration: the duration in seconds for which the toast message is shown. The default is 1.
      • lines: maximum number of lines the text message can have. The default is 1. A value of 0 does not restrict the number of lines at all.

    Declaration

    Swift

    public class func show(message: String, icon: UIImage = FUIToastMessageView.checkmarkImage, inView view: UIView, withDuration duration: Float = 1.0, maxNumberOfLines lines: Int = 1)

    Parameters

    message

    the text of the toast message.

    icon

    the icon in front of the text. The default is a checkmark icon.

    inView

    the container view in which to display the toast message. The toast message will be shown centered in the container.

    duration

    the duration in seconds for which the toast message is shown. The default is 1.

    lines

    maximum number of lines the text message can have. The default is 1. A value of 0 does not restrict the number of lines at all.