Contents

pointerStyleProvider

A closure that returns the pointer style to use when the pointer hovers over the button.

Declaration

@MainActor @preconcurrency var pointerStyleProvider: UIButton.PointerStyleProvider? { get set }

Discussion

To change the appearance of the pointer when it hovers over the button, create a UIButton.PointerStyleProvider closure that returns a UIPointerStyle describing the pointer shape and content effect. Then assign the closure to pointerStyleProvider. For example, the following code listing creates a pointer style that applies a lift effect to the button when the pointer hovers over it.

threadColorButton.pointerStyleProvider = { button, proposedEffect, proposedShape -> UIPointerStyle? in
    let cornerRadius: CGFloat = 4
    let parameters = UIPreviewParameters()
    let shapePath = UIBezierPath(roundedRect: button.bounds, cornerRadius: cornerRadius)
    parameters.shadowPath = shapePath
    let preview = UITargetedPreview(view: proposedEffect.preview.view, parameters: parameters, target: proposedEffect.preview.target)
    
    let rect = button.convert(button.bounds, to: preview.target.container)
    return UIPointerStyle(effect: .lift(preview), shape: .roundedRect(rect, radius: cornerRadius))
}

For more information, see Enhancing your iPad app with pointer interactions.

See Also

Supporting pointer interactions