Contents

dagronf/DSFToggleButton

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

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) 2024 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.

Package Metadata

Repository: dagronf/DSFToggleButton

Stars: 17

Forks: 0

Open issues: 0

Default branch: master

Primary language: swift

License: MIT

Topics: appkit, button, cocoa, macos, objective-c, swift, toggle

README: README.md