测试已测试 | ✗ |
Lang语言 | SwiftSwift |
许可证 | MIT |
发布最后发布 | 2017年3月 |
SwiftSwift 版本 | 3.0 |
SPM支持 SPM | ✗ |
由 Jonathan Cardasis 维护。
将 SizeSlideButton.swift
类添加到您的项目中。
let condensedFrame = CGRect(x: 280, y: 70, width: 32, height: 32) //Width and Height should be equal
let fancyControl = SizeSlideButton(condensedFrame: condensedFrame)
fancyControl.trackColor = UIColor(red: 38/255, green: 50/255, blue: 56/255, alpha: 1)
fancyControl.handle.color = UIColor.white
fancyControl.addTarget(self, action: #selector(newSizeSelected), for: .touchDragFinished)
fancyControl.addTarget(self, action: #selector(sizeSliderTapped), for: .touchUpInside)
self.view.addSubview(fancyControl)
func newSizeSelected(_ sender: SizeSlideButton){
//Do something once a size is selected and the control let go
// You can now use the senders .value for a value between 0 and 1
// Or use the handle's height (handle.height) as a multiplier for size
print("Value: \(sender.value)")
print("Size multiplier: \(sender.handle.height)")
// Ex: self.paintbrush.brushSize = kDefaultBrushSize * sender.handle.height
}
func sizeSliderTapped(_ sender: SizeSlideButton){
//Do something when the button is tapped
print("Tip Tap")
}
输出
init(condensedFrame: CGRect)
将设置压缩框架所处位置的框架(宽度和高度应相等)init(frame: CGRect)
将设置完全展开时框架应处的框架currentSize
用于获取用户选择的大小handlePadding
设置手柄周围的填充(默认为左侧的半径)。效果最好为 <= leftSideRadiushandle.color
是滑块的柄颜色handle.height
/handle.width
获取手柄的大小并可以用作乘以默认常量大小的乘数trackColor
是轨道的颜色value
是介于 0 和 1.0 之间的值,表示手柄相对于轨道上的位置leftSideRadius
和 rightSideRadius
返回展开时框架左侧和右侧的半径currentState
返回控制是否压缩或展开animationType
指定释放控件时使用的动画类型touchUpInside
在触摸控件释放时调用valueChanged
在移动横板时调用touchDown
在检测到长按或正常触摸时调用touchDragFinished
(自定义 UIControlEvent)在滑块选择新值并被释放时调用SizeSlideButton许可协议为MIT许可。有关更多信息,请参阅LICENSE文件。