
- SwiftUI - Home
- SwiftUI - Overview
- SwiftUI vs UIkit
- SwiftUI Environment
- SwiftUI - Environment Setup
- SwiftUI - Basic Components
- SwiftUI - Building First Application
- SwiftUI Views
- SwiftUI - Views
- SwiftUI - Customize Text View
- SwiftUI - Custom Image View
- SwiftUI - Stacks
- SwiftUI Drawing Shapes
- SwiftUI - Shapes
- SwiftUI - Drawing line
- SwiftUI - Drawing Rectangle
- SwiftUI - Drawing Rounded Rectangle
- SwiftUI - Drawing Triangle
- SwiftUI - Drawing Circle
- SwiftUI - Drawing Star
- SwiftUI - Drawing Polygon
- SwiftUI - Drawing Pie chart
- SwiftUI - Using built-in shapes
- SwiftUI - Text
- SwiftUI - Text View
- SwiftUI - Text Input and Output
- SwiftUI - Color
- SwiftUI - Color
- SwiftUI - Colorpicker
- SwiftUI - Gradients
- SwiftUI - Adjust Color
- SwiftUI - Effects
- SwiftUI - Effects
- SwiftUI - Blend Effect
- SwiftUI - BLur Effect
- SwiftUI - Shadow Effect
- SwiftUI - Hover Effect
- SwiftUI - Animations
- SwiftUI - Animations
- SwiftUI - Creating Animations
- SwiftUI - Creating an Explicit Animation
- SwiftUI - Multiple Animations
- SwiftUI - Transitions
- SwiftUI - Asymmetric Transition
- SwiftUI - Custom Transition
- SwiftUI - Image
- SwiftUI - Images
- SwiftUI - Image as Background
- SwiftUI - Rotating Image
- SwiftUI - Media
- SwiftUI - View Layout
- SwiftUI - View Layout
- SwiftUI - View Size
- SwiftUI - View Spacing
- SwiftUI - View Padding
- SwiftUI - UI Controls
- SwiftUI - UI Controls
- SwiftUI - Button
- SwiftUI - CheckBox
- SwiftUI - Menubar
- SwiftUI - Toolbar
- SwiftUI - Search Bar
- SwiftUI - TextField
- SwiftUI - Slider
- SwiftUI - Toggle
- SwiftUI - Pickers
- SwiftUI - Menus
- SwiftUI - List & Tables
- SwiftUI - Lists
- SwiftUI - Static List
- SwiftUI - Dynamic List
- SwiftUI - Customize List
- SwiftUI - Tables
- SwiftUI - Forms
- SwiftUI - Forms
- SwiftUI - Breaking Forms in Sections
- SwiftUI - Event Handling
- SwiftUI - Event Handling
- SwiftUI - Gesture
- SwiftUI - Clipboard
- SwiftUI - Drag and Drop
- SwiftUI - Focus
- SwiftUI - Alert
- SwiftUI - Miscellaneous
- SwiftUI - Containers
- SwiftUI - Navigation
- SwiftUI - Notifications
- SwiftUI - Cross-Platform UI
- SwiftUI - Data
- SwiftUI - Accessibility
- SwiftUI - Framework Integration
- SwiftUI - Framework Integration
- SwiftUI - Interfacing with UIKit
- SwiftUI - Creating macOS App
- SwiftUI Useful Resources
- SwiftUI - Useful Resources
- SwiftUI - Discussion
SwiftUI - Menu Bar
A menubar is a UI element which appears at the top of an application window or can display various options or commands in a list format. Each menubar has its menu, which contains various actions, tasks or buttons.
For example, a menu includes File, Edit, Find, View, etc. SwiftUI does not provide any pre-defined modifier or method to create a menubar. Also, menubar is only supported by macOS 13+, other than macOS, no other Apple platform, such as iOS, iPad, watchOS, etc., supports Menubar.
Creating MenuBar in SwiftUI
In SwiftUI, we can create menubar with the help of MenuBarExtra() method. This method creates a menubar extra with a key that is used as a label. It defines the primary scene of an app. We can also add images and system images in the menu bar. The output of the menubarExtra will display in the actual macOS, not in the simulator.
Syntax
Following is the syntax −
MenuBar(_titleKey: String, content: ()->Content)
Parameters
Following parameters are used by this view −
titleKey: Represent the purpose of the item.
content: A view which displays the elements on the screen.
Example
The following SwiftUI program creates menubar.
import SwiftUI @main struct MyApp: App { var body: some Scene { WindowGroup { ContentView() } // Menu Bar Item MenuBarExtra("MyData", systemImage: "star.fill") { Button("Open") { print("Open Window clicked") } Button("File") { print("Settings clicked") } Button("Project") { print("Settings clicked") } Button("Settings") { print("Settings clicked") } Divider() Button("Quit") { NSApplication.shared.terminate(nil) } } } }
Output

Styling menuBarExtra in SwiftUI
In SwiftUI, we can style menuBarExtra with the help of menuBarExtraStyle() modifier. This modifier provides various styles to style the menubar created by the specified scene. By default, it is style in .automatic, but we can style the menu in .menu and .window.
Syntax
Following is the syntax −
func menuBarExtraStyle(_ style: S) -> some Scene
Example
The following SwiftUI program is used to style menubar.
import SwiftUI @main struct MyApp: App { var body: some Scene { WindowGroup { ContentView() } // Menu Bar Item MenuBarExtra("MyData", systemImage: "star.fill") { Button("Open") { print("Open Window clicked") } Button("File") { print("Settings clicked") } Button("Project") { print("Settings clicked") } Button("Settings") { print("Settings clicked") } Divider() Button("Quit") { NSApplication.shared.terminate(nil) } }.menuBarExtraStyle(.automatic) } }
Output
