A scalable macOS toggle button for Swift and Objective-C that mimics the toggle button of iOS. Inherits from
NSButton. Configurable via code and Interface Builder.
Because sometimes all you want is a nice, big, very visible checkbox.
Adding to your project
Swift Package Manager
https://github.com/dagronf/DSFToggleButton to your project.
pod 'DSFToggleButton', :git => 'https://github.com/dagronf/DSFToggleButton'
to your podfile.
Copy the source files in
Sources/DSFToggleButton into your project.
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.
Drop in a new custom view into your canvas and set its class to
||The color of the button when the state is on, defaults to the off background color|
||Show labels (0 and 1) on the button to increase visual distinction between states|
||Whether to animate state changes|
||Remove any visual flourishes on the control|
||Remove the color when the control is not attached to the key window (standard checkbox behaviour)|
||A block-based callback mechanism (optional) which will be called whenever the button state changes|
Dark mode, green (no labels)
Dark mode, blue with labels
Light mode with labels, high contrast
MIT License Copyright (c) 2020 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.