CreationKit Documentation

Class Banner

public final class Banner  

A banner displays a prominent message and related optional actions.

Banners, like Snackbars, appear temporarily, inform the user of an undertaken action, do not interrupt the user experience, and do not require user input. The primary difference is that they are displayed toward the top of the device.

Methods

make​View(message:​style:​button​Title:​button​Action:​)

public static func makeView(
    message: String,
    style: BannerStyle = .default,
    buttonTitle: String? = nil,
    buttonAction: ((UIButton) -> Void)? = nil
  ) -> BannerViewable  

show(message:​duration:​style:​presentation​Context:​button​Title:​button​Action:​)

public static func show(
    message: String,
    duration: BannerDuration = .short,
    style: BannerStyle = .default,
    presentationContext: BannerPresentationContext = .automatic,
    buttonTitle: String? = nil,
    buttonAction: ((UIButton) -> Void)? = nil
  )  

Displays the Banner.

Parameters

message String

The message to display.

duration Banner​Duration

The duration the snackbar stays on screen.

style Banner​Style

The Style to display the snackbar in.

presentation​Context Banner​Presentation​Context

Use this parameter to specify the scope (window, view controller, view) a banner should appear in. Default is .automatic.

button​Title String?

The button title if any. Leave as nil if you don't want a button to be displayed.

button​Action ((UIButton) -> Void)?

The closure that will be called when the button is tapped. Defaults to nil.

show​Tappable(attributed​Message:​tappable​Text​Color:​data​Detector​Types:​duration:​style:​presentation​Style:​presentation​Context:​should​Hide​After​Tap:​has​Shadow:​text​Tap​Handler:​)

public static func showTappable(
    attributedMessage: NSAttributedString,
    tappableTextColor: UIColor? = nil,
    dataDetectorTypes: UIDataDetectorTypes = .all,
    duration: BannerDuration = .short,
    style: BannerStyle = .default,
    presentationStyle: SwiftMessages.PresentationStyle = .top,
    presentationContext: BannerPresentationContext = .automatic,
    shouldHideAfterTap: Bool = true,
    hasShadow: Bool = true,
    textTapHandler: ((String) -> Void)? = nil
  )  

Displays the Banner with a tappable text portion. This tappable text can be a detectable type, such as a phone number; or the tappable portion can be regular text that has a text tap handler.

Parameters

attributed​Message NSAttributed​String

The message to display. Attributes such as font and text color should be set in the NSAttributedString's attributes.

tappable​Text​Color UIColor?

Optional color for setting the tappable text's color. This setter is for convenience if the tappable text color is not set using NSAttributedString's attributes. Default is UIColor.systemBlue.

data​Detector​Types UIData​Detector​Types

The types of information to detect in the banner.

duration Banner​Duration

The duration the banner stays on screen.

style Banner​Style

The Style to display the banner in.

presentation​Style Swift​Messages.​Presentation​Style

The PresentationStyle to specify whether the banner will be presented at top or bottom of the selected presentation container.

presentation​Context Banner​Presentation​Context

Use this parameter to specify the scope (window, view controller, view) a banner should appear in. Default is .automatic.

should​Hide​After​Tap Bool

Will hide banner after text is tapped. Default is true.

text​Tap​Handler ((String) -> Void)?

The closure that will be called when the text is tapped. Defaults to nil.

make​Tappable​View(attributed​Message:​tappable​Text​Color:​data​Detector​Types:​style:​should​Hide​After​Tap:​has​Shadow:​text​Tap​Handler:​)

public static func makeTappableView(
    attributedMessage: NSAttributedString,
    tappableTextColor: UIColor? = nil,
    dataDetectorTypes: UIDataDetectorTypes = .all,
    style: BannerStyle = .default,
    shouldHideAfterTap: Bool = true,
    hasShadow: Bool = true,
    textTapHandler: ((String) -> Void)? = nil  ) -> BannerViewable