Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/swiftuiux/d3-menu-bar
Customizable multi platform menu bar component with the dark and light scheme support - SwiftUI
https://github.com/swiftuiux/d3-menu-bar
ios macos menu menu-generator menu-navigation menubar swift swiftui
Last synced: about 1 month ago
JSON representation
Customizable multi platform menu bar component with the dark and light scheme support - SwiftUI
- Host: GitHub
- URL: https://github.com/swiftuiux/d3-menu-bar
- Owner: swiftuiux
- License: apache-2.0
- Created: 2022-05-17T09:43:46.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-11-27T11:13:43.000Z (about 2 months ago)
- Last Synced: 2024-11-28T18:41:36.993Z (about 2 months ago)
- Topics: ios, macos, menu, menu-generator, menu-navigation, menubar, swift, swiftui
- Language: Swift
- Homepage:
- Size: 7.63 MB
- Stars: 8
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Menu bar component SwiftUI
[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fswiftuiux%2Fd3-menu-bar%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/swiftuiux/d3-menu-bar)
## Features
- [x] Observing menu selection changes via generic PreferenceKey
- [x] The color intensity automatically adjusts depending on color scheme (Color+Ext.swift) You don't need to set color for every scheme
- [x] Various strategies for the item menu width allocation
- [x] Set scroll position according the initial selection
- [x] Setting custom colors for the component
- [x] Customize menu item style [round or square]
- [x] iOS and macOS support
- [x] Dark and light scheme support## Required
### 1. enum
Define enum with menu items conforming to ```IMenuItem``````Swift
enum MenuItems: String, IMenuItem {
case one = "one"
case two = "two"
case three = "three"
}
```
### 2. create menu bar* `selected` - pass value bound to **@State var selected : MenuItems?**
* `values` - Pass allCases as a parameter```Swift
MenuBar(values: MenuItems.allCases, selected: $selected)
.onSelectionChanged{ item in }
```## Optional
* `strategy` - default strategy for the item menu width allocation is **auto**
| Size strategy | Description |
| --- | --- |
|**fit**| Allocate all affordable space **not scrollable**|
|**auto**| Auto size according the content |
|**flex(CGFloat)**| Set up minimal width|* `color` - default value is **.black**
* `style` - default style is **round**
| Style | Description |
| --- | --- |
|**round**| rounded corners |
|**square**| squared corners |### Component init examples
```Swift
@State var selected : MenuItems?VStack{
MenuBar(values: items, selected: $selected, strategy: .flex(102), color: .green)
MenuBar(values: items, selected: $selected, color: .purple, style: .square)
MenuBar(values: items, selected: $selected, strategy: .fit, color: .blue)
MenuBar(values: items, selected: $selected, color: .red)
}
```
[![click to watch expected UI behavior for the example](https://github.com/swiftuiux/d3-menu-bar/blob/main/Sources/img/img.png)](https://youtu.be/PQRkU7yWUrk)## Code example
Take a look on the example preview in [**MenuContentView.swift**](https://github.com/swiftuiux/d3-menu-bar/blob/main/Sources/d3-menu-bar/example/MenuViewExample.swift) or create a project, add the package and put **MenuContentView()** in **ContentView()**
## Used in
[Auto scrollable header menu - SwiftUI & Combine](https://github.com/swiftuiux/food-scrollable-menu-list)## Documentation(API)
- You need to have Xcode 13 installed in order to have access to Documentation Compiler (DocC)
- Go to Product > Build Documentation or **⌃⇧⌘ D**