How it works
HighlightHoverEffect is one of SwiftUI's built-in hover effects, applied when a pointer-based input device — such as a trackpad, mouse, or Apple Pencil — moves over an interactive view. It morphs the content into a soft, rounded highlight that visually lifts the element toward the pointer, giving people clear feedback that the view is a hover target before they commit to a tap or click. Reach for it on controls and tappable surfaces where you want the platform's standard highlight treatment rather than a custom animation, letting the system match the look and timing of native interface elements.
Apply the effect with hoverEffect(_:)
You rarely construct
HighlightHoverEffectby name. Instead you attach it through thehoverEffect(_:)view modifier, which takes a hover-effect value and installs the corresponding behavior on the view. In the example,.hoverEffect(.highlight)is what brings the highlight treatment to theButton.Select it through the .highlight shorthand
The
.highlightmember is the type-inferred shorthand that resolves toHighlightHoverEffect. Passing it to the modifier — as in.hoverEffect(.highlight)— is equivalent to naming the struct directly, and is the idiomatic way to request this specific effect among the available hover effects.Attach it to a hover-capable view
The effect needs a view that participates in pointer interaction to react against. Here it sits on a
Buttonstyled with.buttonStyle(.bordered); the bordered control gives the highlight a defined shape to grow into as the pointer arrives. Any interactive view in the hierarchy can host the modifier.Let the system drive shape and timing
Once applied,
HighlightHoverEffectautomatically derives its rounded highlight geometry from the host view's bounds and animates in and out as the pointer enters and leaves — no parameters, frames, or animation curves to configure. The surroundingLabelwithcursorarrow.raysonly annotates the demo; the effect itself is entirely declared by the single modifier.
.hoverEffect(.highlight) to .hoverEffect(.lift) and hover with a trackpad to contrast the highlight against the lift effect's scale-and-shadow treatment.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.
struct HighlightHoverEffectDemo: View {
var body: some View {
VStack(spacing: 16) {
Text("Hover Effect: Highlight")
.font(.headline)
Button("Hover Over Me") {}
.buttonStyle(.bordered)
.hoverEffect(.highlight)
Label("Highlights on pointer hover", systemImage: "cursorarrow.rays")
.foregroundStyle(.secondary)
.font(.caption)
}
.padding()
}
}