Loading...

Adding Tooltips to SwiftUI Views on macOS

question swiftui macos
Ram Patra Published on September 29, 2025

Tooltips are a subtle but powerful way to improve usability on macOS. They give users extra context when they hover over buttons, text, or icons without cluttering the main UI. SwiftUI makes it easy to add tooltips — and also flexible enough to create custom ones when you need more control.

The Default Tooltip: .help

The simplest way to add a tooltip in SwiftUI is with the .help(...) modifier. This attaches a native macOS tooltip to any view:

Button("Hover me") {
    print("Clicked")
}
.help("This is a tooltip shown when you hover.")

On macOS, this displays the familiar yellow system tooltip bubble. On iOS, .help instead contributes to accessibility features like VoiceOver.

Multiline Tooltips with .help

If you want more than one line of text, you can simply add line breaks:

Button("Hover me") {}
    .help("This is line one.\nThis is line two.")

The system tooltip will wrap and display multiple lines. This covers most basic cases where you just need to explain an action or shortcut.

Custom Tooltips for More Control

Sometimes you need more than plain text: maybe an icon, styled text, or explanatory notes. SwiftUI doesn’t style .help, but you can build your own tooltip using onHover and an overlay.

Here’s a reusable component:

import SwiftUI

struct Tooltip<Content: View>: ViewModifier {
    @State private var isHovering = false
    let tooltipContent: Content
    
    init(@ViewBuilder content: () -> Content) {
        self.tooltipContent = content()
    }
    
    func body(content: ContentOf<Self>) -> some View {
        content
            .onHover { hovering in
                withAnimation(.easeInOut(duration: 0.2)) {
                    isHovering = hovering
                }
            }
            .overlay(alignment: .top) {
                if isHovering {
                    tooltipContent
                        .padding(8)
                        .background(
                            RoundedRectangle(cornerRadius: 6)
                                .fill(Color(.windowBackgroundColor))
                        )
                        .overlay(
                            RoundedRectangle(cornerRadius: 6)
                                .stroke(Color.gray.opacity(0.2))
                        )
                        .shadow(radius: 3)
                        .offset(y: -40)
                        .transition(.opacity.combined(with: .scale))
                }
            }
    }
}

extension View {
    func tooltip<Content: View>(@ViewBuilder _ content: () -> Content) -> some View {
        self.modifier(Tooltip(content: content))
    }
}

And here’s how you use it:

Image(systemName: "star.fill")
    .resizable()
    .frame(width: 40, height: 40)
    .foregroundStyle(.yellow)
    .tooltip {
        VStack(alignment: .leading) {
            Text("Favorites")
                .font(.headline)
            Text("Mark this item as a favorite to access it quickly.")
                .font(.caption)
                .foregroundColor(.secondary)
        }
    }

Now you have full control over your tooltip’s design: multiple text styles, icons, even custom layouts.


Wrapping Up

  • Use .help for the default macOS tooltip — it’s native, accessible, and quick.
  • Add \n for multiline content if you just need more space.
  • Build a custom tooltip with onHover and overlays when you want rich, styled, or interactive hints.

With these three approaches, you can cover everything from simple hints to fully branded helper popups, while still feeling right at home on macOS.

Presentify

Take your presentation to the next level.

FaceScreen

Put your face and name on your screen.

KeyScreen

Show keypresses on your screen.

ToDoBar

Your to-dos on your menu bar.

SimpleFill

Fill forms using your right-click menu.

IconSim

Preview your Mac app icons.

Ram Patra Published on September 29, 2025
Image placeholder

Keep reading

If this article was helpful, others might be too

question swiftui March 29, 2024 How to group different style modifiers and reuse them across multiple SwiftUI views?

In SwiftUI, you can create custom view modifiers to encapsulate common styling configurations and reuse them across different views. Here’s how you can create and reuse a custom view modifier:

question swiftui swift February 19, 2025 How to change the window level to floating, popUpMenu, etc. in SwiftUI?

When developing macOS applications with SwiftUI, you might need to create floating windows that stay on top of other windows. While modern macOS versions (15+) make this straightforward with the .windowLevel(.floating) modifier, supporting older versions requires a different approach. In this post, I’ll show you how to create floating windows that work across different macOS versions.

question swiftui iOS April 2, 2024 How to force an app or a view to open in landscape only mode in iOS using SwiftUI?

In SwiftUI, you can force an app to open in landscape mode by configuring the supported interface orientations in your app’s target settings. Here’s a step-by-step guide to configuring interface orientations in Xcode:

Like my work?

Please, feel free to reach out. I would be more than happy to chat.