TechnologiesSwiftUIHover and Pointer Effects

AutomaticHoverEffect struct

iOSmacOStvOSwatchOSvisionOS✓ renders

The default hover effect based on the surrounding context.

How it works

AutomaticHoverEffect is the hover effect that lets the system decide how a view should respond when a pointer moves over it, rather than committing you to a specific look like highlight or lift. It is the value behind HoverEffect.automatic, and it exists so you can opt a view into pointer interactions without hard-coding an appearance that might not suit the platform, the device, or the kind of view being decorated. Reach for it whenever you want sensible, platform-appropriate hover feedback on iPadOS, visionOS, or other pointer-aware environments and you would rather defer the exact treatment to SwiftUI.

  1. Apply it through hoverEffect(_:)

    You don't construct AutomaticHoverEffect directly; you attach it with the hoverEffect(_:) view modifier, which takes a HoverEffect and applies it when a pointer hovers the view. In the example both the Text("Hover over me") and the Button("Tap or Hover") receive their behavior from a single .hoverEffect(...) call.

  2. Select it with HoverEffect.automatic

    Passing .automatic is what resolves to an AutomaticHoverEffect instance, telling SwiftUI to pick the effect for you. Writing .hoverEffect(.automatic) on a view is the entire opt-in: there are no parameters to tune, because choosing the appearance is precisely the responsibility you are handing back to the system.

  3. Let the effect adapt to the view it decorates

    Because the choice is automatic, the same .hoverEffect(.automatic) can read differently depending on what it modifies. The decorated Text with its .background(.blue.opacity(0.2), in: RoundedRectangle(cornerRadius: 12)) and the Button styled with .buttonStyle(.borderedProminent) each get hover feedback the system deems suitable for that shape and role.

  4. Position it relative to other modifiers

    The effect applies to the view as configured up to that point in the modifier chain, so order matters. Placing .hoverEffect(.automatic) after .background(...) on the Text, and after .buttonStyle(.borderedProminent) on the Button, ensures the hover treatment is derived from the fully styled, rounded, padded result.

Try it — Swap .hoverEffect(.automatic) on the Text("Hover over me") for .hoverEffect(.highlight) and compare the two views under a pointer to see how the automatic effect's system-chosen treatment differs from a fixed one.

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.

AutomaticHoverEffect.swift
struct AutomaticHoverEffectDemo: View {
    var body: some View {
        VStack(spacing: 16) {
            Text("Hover over me")
                .padding()
                .background(.blue.opacity(0.2), in: RoundedRectangle(cornerRadius: 12))
                .hoverEffect(.automatic)

            Button("Tap or Hover") { }
                .buttonStyle(.borderedProminent)
                .hoverEffect(.automatic)
        }
        .padding()
    }
}
Live preview
Hover over me Tap or Hover
Hover over me Tap or Hover
swift → lexer → parser → sema → uiir → canvas Open in Studio ↗
What's new in SwiftUI 27 →