Home IOS Development Creating Tooltips with TipKit and SwiftUI in iOS 17

Creating Tooltips with TipKit and SwiftUI in iOS 17

Creating Tooltips with TipKit and SwiftUI in iOS 17


It’s all the time essential to make your app as intuitive as attainable. Nonetheless, for some options, it might be useful to supply further info to show customers the best way to use them successfully. That’s the place TipKit is available in. Launched in iOS 17, TipKit is a framework for displaying ideas in your app, permitting builders to supply extra steerage and guaranteeing customers to take advantage of your app’s options.

On this tutorial, we are going to discover the TipKit framework and see the best way to create ideas for a demo app utilizing SwiftUI.

Utilizing the TipKit Framework

To make use of the TipKit framework, it’s important to first import it into your challenge:

Understanding the Tip Protocol

To create a tip utilizing the TipKit framework, you’ll want to undertake the Tip protocol to configure the content material of the tip. Ideas include a title and a brief description. Optionally, you may embrace a picture to affiliate with the tip.


For instance, to setup the “Save as favourite” tip, you may create a struct that conforms to the Tip protocol like this:

If you wish to add a picture to the tip, you may outline the picture property:

Displaying Ideas Utilizing Popover and TipView

The TipKit framework supplies the pliability to show ideas both as a popover or an inline view. Within the popover view, it seems over your app’s UI, which may very well be a button, a picture, or different UI components. Then again, the inline view behaves like different customary UI components, adjusting its place to suit round different views, guaranteeing that no UI components are blocked.


To point out the tip as an inline view, you may create an occasion of TipView and cross it the tip to show. Right here is an instance:

If you wish to show a tip as a popover view, you may connect the modifier popoverTip to the button or different UI components:

To allow the looks of ideas inside your apps, the ultimate step is to configure the Ideas heart. Assuming your Xcode challenge is known as TipKitDemo, you may swap over to TipKitDemoApp and replace the struct like this:

We will customise the show frequency and the info retailer location by using the configure technique of the Ideas heart. Within the code snippet above, the show frequency is about to fast, which suggests the information will probably be proven instantly. If you happen to favor the tricks to seem as soon as each 24 hours, you should utilize the .day by day possibility. Furthermore, you could have the pliability to customise the show frequency to any desired time interval, as demonstrated within the following instance:

With the Ideas heart configured, you must be capable of see the information when working the app within the simulator.

Previewing the Ideas


If you wish to preview the information within the preview canvas, you additionally have to arrange the Ideas heart within the #Preview block. Right here is an instance:

An essential level to notice is the inclusion of an additional line of code for resetting the info retailer. As soon as a tip is dismissed, it received’t be displayed once more within the app. Nonetheless, in terms of previewing the app and guaranteeing that the information are persistently proven, it’s endorsed to reset the info retailer.

Dismissing the Ideas

Customers have the choice to dismiss a tip by tapping the X image. If there’s a have to dismiss the tip view programmatically, you may make the most of the invalidate technique and supply a particular cause as demonstrated beneath:

The explanation actionPerformed signifies that the consumer carried out the motion that the tip describes.

Specifying Show Guidelines

The Tip protocol has an elective property so that you can set tup the show guidelines of the tip. It helps two varieties of guidelines: parameter-based and event-based. Parameter-based guidelines are perfect for displaying ideas primarily based on particular Swift worth sorts. Then again, event-based guidelines allow you to outline actions that should be fulfilled earlier than a consumer turns into eligible to obtain a tip.

For example, the favourite tip ought to solely be displayed after the “Getting Began” tip. We will arrange the parameter-based rule like this:

Within the code above, we introduce a parameter referred to as hasViewedGetStartedTip utilizing the @Parameter macro, initially set to false. The guidelines property incorporates a rule that validates the worth of the hasViewedGetStartedTip variable, indicating that the tip needs to be displayed when the worth is true.

When the picture is tapped, the “Getting Began” tip is dismissed. In the identical closure, we are able to set the worth of hasViewedGetStartedTip to true.

Upon launching the app, solely the “Getting Began” tip is displayed. Nonetheless, when you faucet the picture to dismiss the tip, the app then presents the “Favourite” tip.



On this tutorial, we coated the TipKit framework accessible on iOS 17. It’s a helpful software for showcasing hidden app options and instructing customers the best way to successfully make the most of them. With TipKit, you may effortlessly create and show tricks to improve the consumer expertise. If you happen to discover TipKit helpful, think about integrating it into your subsequent app replace for added advantages.

To be taught extra about different SwiftUI ideas, you may try our Mastering SwiftUI ebook.



Please enter your comment!
Please enter your name here