TechnologiesSwiftUIHover and Pointer Effects

HoverEffect struct

iOSmacOStvOSwatchOSvisionOS✓ renders

An effect applied when the pointer hovers over a view.

How it works

HoverEffect describes the visual effect a view shows while a pointer hovers over it, giving people targeting feedback on platforms that have an indirect pointer, such as iPadOS with a trackpad or visionOS. Rather than animating hover transitions yourself, you choose one of the system-defined effects and let SwiftUI morph the view as the pointer enters and leaves it. Reach for it whenever an interactive element should signal that it's a valid target — buttons, list rows, images, or any custom control — and you want behavior that matches the platform's conventions and respects accessibility settings.

  1. Apply an effect with hoverEffect(_:)

    You don't construct a HoverEffect directly; instead you pass one to the hoverEffect(_:) modifier, which installs it on the view and registers the view as a hover target. In the example, .hoverEffect(.highlight) attaches an effect to the Image, and .hoverEffect(.lift) attaches one to the Text capsule.

  2. Choose the .highlight effect

    The highlight effect morphs the pointer into the shape of the view and draws a soft highlight behind it, which suits content-like targets such as icons. Here .highlight is applied to the star.fill Image, so the pointer settles onto the glyph as it hovers.

  3. Choose the .lift effect

    The lift effect raises the view above the surrounding content with a shadow and slight scale, reading as a tappable, button-like surface. The example uses .lift on the Text("Hover Me") label, which already has a blue Capsule() background, so the whole pill appears to float on hover.

  4. Fall back to .automatic

    When you want the system to pick an appropriate effect for the context, use .automatic, the default effect type. The two cards in the example name .highlight and .lift explicitly, but swapping either for .automatic lets SwiftUI choose based on the platform and the kind of view.

Try it — Change .hoverEffect(.lift) on the Text("Hover Me") capsule to .hoverEffect(.highlight) and compare it against the star to see how lift's floating shadow differs from highlight's shape-conforming glow.

Example & preview

Press Run live & edit to compile it in your browser — then edit the Swift on the left and the preview re-renders live.

HoverEffect.swift
struct HoverEffectDemo: View {
    var body: some View {
        VStack(spacing: 24) {
            Image(systemName: "star.fill")
                .font(.largeTitle)
                .padding()
                .hoverEffect(.highlight)

            Text("Hover Me")
                .padding()
                .background(.blue, in: Capsule())
                .foregroundStyle(.white)
                .hoverEffect(.lift)
        }
        .padding()
    }
}
Live preview
Hover Me
Hover Me
swift → lexer → parser → sema → uiir → canvas Open in Studio ↗
What's new in SwiftUI 27 →