A drop-in `NSComboButton` replacement with pre macOS 13 support.

Overview

DSFComboButton

Swift Package Manager

A drop-in NSComboButton replacement control with pre macOS 13 support.

For when you want to adopt NSComboButton but have to maintain compatibility back to 10.13.

Features

DSFComboButton attempts to match the NSComboButton control API as closely as possible. The programmatic interface is almost identical, however (unfortunately) Interface Builder support in a custom control is very limited so I've done as best I can.

Split style

Split style

  • Click on the leading side of the button to perform a 'default' action
  • Click on the down arrow to present a menu

Unified style

Unified style

  • Click on the button to perform a 'default' action
  • Click and hold to present a menu

Styles

style description
.split A style that separates the button’s title and image from the menu indicator people use to activate the button.
.unified A style that unifies the button’s title and image with the menu indicator.

Properties

property type description
style DSFComboButton.Style The control style to use
title String The text to display on the control
image NSImage The image to display on the control
imageScaling NSImageScaling How the image scales
target AnyObject The target for the button's action
action Selector The selector to call on the target
controlSize NSControl.ControlSize The size of the control

Setting the popup menu

via code

Assign an NSMenu instance to .menu

let button = DSFComboButton()
button.menu = NSMenu(...)

via Interface Builder

  1. Drop an NSMenu instance into your XIB/Storyboard
  2. Ctrl-Drag from the DSFComboButton control on the storyboard to the menu, select menu outlet

Setting the button's target/action

via code

let button = DSFComboButton()
button.target = /*some controller*/
button.action = #selector(buttonPressed(_:))

via Interface Builder

ctrl-drag from the DSFComboButton control to the code.

License

MIT License

Copyright (c) 2022 Darren Ford

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
You might also like...
Collection of native Swift extensions to boost your development. Support tvOS and watchOS.
Collection of native Swift extensions to boost your development. Support tvOS and watchOS.

SparrowKit Collection of native Swift extensions to boost your development. Support iOS, tvOS and watchOS. If you like the project, don't forget to pu

Swift-when - Expression switch support in Swift

Swift When - supporting switch expressions in Swift! What is it? Basically, it a

Add “Launch at Login” functionality to your macOS app in seconds
Add “Launch at Login” functionality to your macOS app in seconds

LaunchAtLogin Add “Launch at Login” functionality to your macOS app in seconds It's usually quite a convoluted and error-prone process to add this. No

macOS system library in Swift

SystemKit A macOS system library in Swift based off of libtop, from Apple's top implementation. For an example usage of this library, see dshb, a macO

A macOS application displaying the thermal, voltage and current sensor values.
A macOS application displaying the thermal, voltage and current sensor values.

Sensors About A macOS application displaying the thermal, voltage and current sensor values. License Project is released under the terms of the MIT Li

ALO sync allows you to sync resources form an ALO endpoint to your macOS file system.
ALO sync allows you to sync resources form an ALO endpoint to your macOS file system.

ALO sync allows you to sync resources form an ALO endpoint to your macOS file system. Prerequisites macOS 11 No support for search* No suppor

Simple utility to change macOS Big Sur menu bar color by appending a solid color or gradient rectangle to a wallpaper image
Simple utility to change macOS Big Sur menu bar color by appending a solid color or gradient rectangle to a wallpaper image

Change menu bar color in macOS Big Sur Simple utility to change macOS Big Sur menu bar color by appending a solid color or gradient rectangle to a wal

A set of utilities (vmcli + vmctl) for macOS Virtualization.framework

VMCLI A set of utilities to help you manage VMs with Virtualization.framework Installation Prerequisites macOS Big Sur (11+) XCode.app installed # mak

SwiftyUpdateKit is a framework for iOS and macOS.
SwiftyUpdateKit is a framework for iOS and macOS.

SwiftyUpdateKit is a framework for iOS and macOS. This framework supports for a user to update your app when new app version is released on the App Store.

Comments
  • request

    request

    hi, nice control the problem is when you select a nsmenuitem this function is called func splitMenuAction(_ sender: Any) but you can't know what is dsfcombobutton are the parent ?

    suggestion set func splitMenuAction(_ sender: Any,_ combo:Any) or use for each NSMenuItem use the property

    representedObject for set the dsfcombobutton pointer.

    the goal are when you select a item, update the title of dsfcombobutton

    thanks,

    opened by DevulderJeanPaul 1
Owner
Darren Ford
Darren Ford
UIPredicateEditor aims to be come a drop-in replacement of NSPredicateEditor for iOS, iPadOS and Mac Catalyst targets.

UIPredicateEditor UIPredicateEditor aims to be come a drop-in replacement of NSPredicateEditor for iOS, iPadOS and Mac Catalyst targets. The plan is t

Nikhil Nigade 1 Jun 6, 2022
ETFKit - Designed to be a drop-in replacement for JSONDecoder/JSONEncoder

ETFKit Encoder/decoder for Erlang's External Term Format (version 131). Designed to be a drop-in replacement for JSONDecoder/JSONEncoder. Simply repla

Swiftcord 2 Jun 10, 2022
Mouse Finder is a fun replacement for the system Finder icon in the Dock.

Mouse Finder Mouse Finder is a fun replacement for the system Finder icon in the Dock. It mostly works exactly like the system icon, with one importan

Neil Sardesai 432 Dec 22, 2022
macOS utility for converting fat-frameworks to SPM-compatible XCFramework with arm64-simulator support

xcframework-maker macOS utility for converting fat-frameworks to SPM-compatible XCFramework with arm64-simulator support. ?? Description make-xcframew

Dariusz Rybicki 312 Dec 22, 2022
This is a Swift package with support for macOS that allows to start Java Jar's with the default or a custom JVM.

Jar.swift jar runner for macos Jar.swift is created and maintaned with ❥ by Sascha Muellner. What? This is a Swift package with support for macOS that

Swift Package Repository 1 Nov 11, 2021
Mechanical editing support for Package.swift manifests

Mechanical editing support for Package.swift manifests. Implements Swift Evolution proposal SE-301

Owen Voorhees 9 Jan 4, 2023
Swift Sequences are limited in that they don't support Iterators with a throwing next().

FailableSequence Swift Sequences are limited in that they don't support Iterators with a throwing next(). There are several use cases for such sequenc

Berik Visschers 0 Dec 6, 2021
Support library of BudouX.swift to handle HTML

HTMLBudouX.swift HTMLBudouX.swift is a support library of BudouX.swift to handle HTML. Detail about BudouX.swift is here Usage You can translate an HT

griffin-stewie 1 Dec 31, 2021
Proper YAML support for Objective-C. Based on recommended libyaml.

YAML.framework for Objective-C Based on C LibYAML library (http://pyyaml.org/wiki/LibYAML) by Kirill Simonov. YAML.framework provides support for YAML

Mirek Rusin 236 Aug 29, 2022
BCSwiftTor - Opinionated pure Swift controller for Tor, including full support for Swift 5.5 and Swift Concurrency

BCSwiftTor Opinionated pure Swift controller for Tor, including full support for

Blockchain Commons, LLC — A “not-for-profit” benefit corporation 4 Oct 6, 2022