一个 macOS NSSwitch 风格的开关按钮,可以缩放到任何尺寸。支持 Swift、SwiftUI 和 Objective-C。
因为有时你需要的只是一个漂亮、大且非常醒目的开关按钮/复选框。
将 https://github.com/dagronf/DSFToggleButton
添加到你的项目中。
由于 DSFToggleButton
继承自 NSButton
,它的行为与普通复选框相同。你可以像操作 NSButton
一样,以编程方式设置状态或其启用状态,例如,包括手动绑定。
控件本身不定义其大小,因此你可以将其设置为任意大小。 由于所有绘图都是可缩放的,因此控件在任何你想要的尺寸下都看起来很棒。
在你的画布中拖入一个新的自定义视图,并将其类设置为 DSFToggleButton
。
变量 | 类型 | 描述 |
---|---|---|
color |
NSColor |
按钮在开启状态下的颜色,默认为关闭状态的背景颜色 |
showLabels |
Bool |
在按钮上显示标签(0 和 1),以增强状态之间的视觉区分 |
animated |
Bool |
是否动画显示状态变化 |
highContrast |
Bool |
移除控件上的任何视觉装饰 |
回调 | 描述 |
---|---|
stateChangeBlock |
一个基于 Block 的回调机制(可选),将在按钮状态更改时调用 |
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.