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 swift September 2, 2024 Combine in SwiftUI and how you can rewrite the same code using async await

Combine is Apple’s declarative framework for handling asynchronous events and data streams in Swift. Introduced in SwiftUI and iOS 13, Combine leverages reactive programming principles, allowing developers to process values over time and manage complex asynchronous workflows with clarity and efficiency.

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 macos September 3, 2024 Two ways to open a window programmatically in SwiftUI

SwiftUI provides an openWindow environment variable on macOS that allows you to open windows programmatically. Here’s how you can use it to open a new window when a button is clicked:

Like my work?

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