UIToolTipInteraction
An interaction object that makes it possible to show a tooltip when hovering a pointer over a view or control.
Declaration
@MainActor class UIToolTipInteractionOverview
To show a tooltip when the pointer hovers over a view, add a UIToolTipInteraction object to the view. For example, the following code listings shows how to add a tooltip to a label:
let label = UILabel()
label.text = "Label with a tooltip"
let tooltipInteraction = UIToolTipInteraction(defaultToolTip: "The label's tooltip.")
label.addInteraction(tooltipInteraction)If you want your app to determine the tooltip text at a later time — for instance, to reflect the current state of your app — set the interaction’s delegate property to an object that conforms to the UIToolTipInteractionDelegate protocol.
To add a tooltip to a control derived from UIControl, use the convenience property toolTip; for example, to add a tooltip to the button:
let button = UIButton(configuration: configuration, primaryAction: action)
button.toolTip = "Click to buy this item. You'll have a chance to change your mind before confirming your purchase."Setting the toolTip property creates a tooltip interaction for the control, which you can retrieve from the toolTipInteraction property.