Loading...

How to render the icon on a menu bar as a template in SwiftUI?

question swiftui
Ram Patra Published on March 6, 2023

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.

The code would look like this:

import SwiftUI

@main
struct ToDoBarApp: App {
    var body: some Scene {
        MenuBarExtra {
            YourView()
        } label: {
            Image("MenuBarIcon").renderingMode(.template)
        }
    }
}
Presentify

Take your presentation to the next level.

FaceScreen

Put your face and name on your screen.

ToDoBar

Your to-dos on your menu bar.

Ram Patra Published on March 6, 2023
Image placeholder

Keep reading

If this article was helpful, others might be too

question swiftui swift September 13, 2024 How to add a character limit to a TextField in SwiftUI?

To add a character length limit to a TextField in SwiftUI, you can use a combination of Swift’s .onChange, .onPasteCommand modifier, and string manipulation to limit the number of characters the user can enter.

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 April 2, 2024 How to declare an array of Views in SwiftUI?

In SwiftUI, you can declare an array of View using the standard Swift array syntax. Here’s how you can do it: