https://github.com/iSapozhnik/Menu
The most customizable menu for macOS apps.
https://github.com/iSapozhnik/Menu
custom-menus dropdown mac macos menu nsmenu nspopupbutton nswindow nswindowcontroller popup swift
Last synced: 4 months ago
JSON representation
The most customizable menu for macOS apps.
- Host: GitHub
- URL: https://github.com/iSapozhnik/Menu
- Owner: iSapozhnik
- License: mit
- Created: 2020-04-14T20:09:31.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2021-11-19T22:04:48.000Z (over 3 years ago)
- Last Synced: 2025-01-22T09:37:58.179Z (4 months ago)
- Topics: custom-menus, dropdown, mac, macos, menu, nsmenu, nspopupbutton, nswindow, nswindowcontroller, popup, swift
- Language: Swift
- Homepage:
- Size: 1.82 MB
- Stars: 119
- Watchers: 5
- Forks: 21
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Menu


[](https://opensource.org/licenses/MIT)
[](https://swiftpackageindex.com/iSapozhnik/Menu)>Fully customizable macOS drop-down menu. It includes **30** settings you can play with.

## Requirements
* Xcode 11+
* macOS 10.12+
* Swift 5.0 and higher## Installation
Since this is a Swift Package, the installation process is pretty stright forward.
### Manual way
Update your `Package.swift` dependencies:```
dependencies: [
.package(url: "https://github.com/iSapozhnik/Menu", from: "1.10.1")
]
```### Via Xcode:
1. Go to `File -> Swift Packages -> Add Package Dependency`.
2. Put GitHub URL `https://github.com/iSapozhnik/Menu` and click `Next`
3. Select the latest version
4. Click `Finish`## What can be customized? Everything!
```swift
public protocol Configuration {
var titleBottomSpace: CGFloat { get }
var titleFont: NSFont? { get }
var titleColor: NSColor { get }
var backgroundColor: NSColor { get }
var cornerRadius: CGFloat { get }
var hasShadow: Bool { get }
var appearsBelowSender: Bool { get }
var presentingOffset: CGFloat { get }
var animationDuration: TimeInterval { get }
var contentEdgeInsets: NSEdgeInsets { get }
var maximumContentHeight: CGFloat? { get }
var separatorColor: NSColor { get }
var separatorThickness: CGFloat { get }
var separatorHorizontalPadding: Padding.Horizontal { get }
var separatorVerticlaPadding: Padding.Vertical { get }
var rememberSelection: Bool { get }
var textAlignment: Alignment { get }
var iconAlignment: Alignment { get }
var menuItemFont: NSFont? { get }
var menuItemHeight: CGFloat { get }
var menuItemHoverBackgroundColor: NSColor { get }
var menuItemTextColor: NSColor { get }
var menuItemHoverTextColor: NSColor { get }
var menuItemCheckmarkColor: NSColor { get }
var menuItemHoverCheckmarkColor: NSColor { get }
var menuItemCheckmarkHeight: CGFloat { get }
var menuItemCheckmarkThikness: CGFloat { get }
var menuItemHorizontalSpacing: CGFloat { get }
var menuItemImageHeight: CGFloat? { get }
var menuItemImageTintColor: NSColor? { get }
var menuItemHoverImageTintColor: NSColor? { get }
var menuItemHoverAnimationDuration: TimeInterval { get }
}
```
## How to use```swift
import Cocoa
import Menuclass ViewController: NSViewController {
private let myMenu = Menu(with: "Select a search engine:")@IBOutlet var showMenuButton: NSButton!
override func viewDidLoad() {
super.viewDidLoad()let bing = MenuItem("Bing search", image: Icn.bing.image, action: { [weak self] in
self?.showMenuButton.title = "Bing"
})
let item = MenuItem("DuckDuckGo search", image: Icn.duck.image, action: { [weak self] in
self?.showMenuButton.title = "DuckDuckGo"
})
let google = MenuItem("Google search", image: Icn.google.image, action: { [weak self] in
self?.showMenuButton.title = "Google"
})
let longText = MenuItem("Some very-very-very long text with no icon", action: { [weak self] in
self?.showMenuButton.title = "Some very long text"
})
let emojiItem = MenuItem("Emojis are here 😎🚀", action: { [weak self] in
self?.showMenuButton.title = "Emojis are here 😎🚀"
})
let exit = MenuItem("Exit", image: Icn.exit.image, action: {
NSApplication.shared.terminate(nil)
})
let separator = MenuItem.separator()
let menuItems = [
bing,
item,
google,
separator,
longText,
emojiItem,
separator,
exit
]myMenu.addItems(menuItems)
}@IBAction func didClickButton(_ sender: NSButton) {
myMenu.show(from: sender)
}
}
```## Examples
In this section I've collected some examples of what can be i,plemented do using **Menu** control. On the left side some random example from Dribbble and on the right side my implementation.
| Dribbble | Menu | Code |
| ------------- |:-------------:|:-------------:|
| [link](https://dribbble.com/shots/4233782-Snooze-notifications-in-Twist) | |
|  |  | |
| [link](https://dribbble.com/shots/7055473-Dropdowns) | | |
|  |  | [code](examples/examples.md) |## Credits
Created and maintained by [**@iSapozhnik**](https://twitter.com/iSapozhnik).
## License
Released under the MIT License. See `LICENSE` for details.
>**Copyright © 2020-present Sapozhnik Ivan.**