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 macOS January 26, 2024 How to hide the title bar in a SwiftUI macOS app?

Let’s say you have a view named ContentView and your main App file looks like this:

question swiftui swift October 30, 2023 How to convert Color type to hex and vice-versa while retaining alpha information?

The below should work both on macOS and iOS with one minor change. That is, use UIColor instead of NSColor if you’re planning to use it for iOS.

question swiftui March 6, 2023 How to render the icon on a menu bar as a template in SwiftUI?

Setting your app’s icon on the menu bar as a template makes it to adapt to light and dark modes automatically without you doing anything. To do this, you have to use this constructor of MenuBarExtra class.

Like my work?

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