Swiftpack.co - dagronf/DSFToggleButton as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by dagronf.
dagronf/DSFToggleButton 7.0.3
A macOS toggle button (inheriting from NSButton) that mimics iOS's UISwitch
⭐️ 13
🕓 1 year ago
macOS
.package(url: "https://github.com/dagronf/DSFToggleButton.git", from: "7.0.3")

DSFToggleButton

A macOS NSSwitch-style toggle button scalable to any size. Supports Swift, SwiftUI and Objective-C.

Why

Because sometimes all you want is a nice, big, very visible toggle button/checkbox.

Adding to your project

Swift Package Manager

Add https://github.com/dagronf/DSFToggleButton to your project.

Usage

Since DSFToggleButton inherits from NSButton, its behaviour is the same as for a regular checkbox. You can programatically set the state or its enabled states just as you would for an NSButton for example, including manual bindings.

The control itself does not define its size, so you can make it as big or as small as you'd like. As all the drawing is scalable, the control will look great at any size you want.

Interface builder

Drop in a new custom view into your canvas and set its class to DSFToggleButton.

Configuration

Variable Type Description
color NSColor The color of the button when the state is on, defaults to the off background color
showLabels Bool Show labels (0 and 1) on the button to increase visual distinction between states
animated Bool Whether to animate state changes
highContrast Bool Remove any visual flourishes on the control
Callback Description
stateChangeBlock A block-based callback mechanism (optional) which will be called whenever the button state changes

Screenshots

Dark mode, green (no labels)

Dark mode, blue with labels

Light mode with labels, high contrast

Interface Builder

License

MIT License

Copyright (c) 2023 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.

GitHub

link
Stars: 13
Last commit: 1 year ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics