DTRuler
介绍
简单的尺子输入控制。
安装
要求
iOS 8.4+
CocoaPods
要安装 DTRuler,在你的 Podfile 中添加依赖项
pod "DTRuler"
Carthage
要安装 DTRuler,请将依赖项添加到您的 Cartfile 中
github "danjiang/DTRuler"
carthage update --platform ios
使用方法
导入
import DTRuler
示例使用
// Float with step as 0.1
let scale = 78.9
let ruler = DTRuler(scale: .float(scale), minScale: .float(9), maxScale: .float(999), width: view.bounds.width - 50)
// or Integer with step as 1
let scale = 59
let ruler = DTRuler(scale: .integer(scale), minScale: .integer(10), maxScale: .integer(100), width: view.bounds.width - 50)
ruler.delegate = self
extension ViewController: DTRulerDelegate {
func didChange(on ruler: DTRuler, withScale scale: DTRuler.Scale) {
switch scale {
case .float(let f):
print(f)
case .integer(let i):
print(i)
}
}
自定义
struct Colorful: DTRulerTheme {
var backgroundColor: UIColor {
return UIColor.lightGray
}
var pointerColor: UIColor {
return UIColor.gray
}
var majorScaleColor: UIColor {
return UIColor.darkGray
}
var minorScaleColor: UIColor {
return UIColor.darkGray
}
var labelColor: UIColor {
return UIColor.darkGray
}
}
DTRuler.theme = Colorful()