DTRuler 1.0.2

DTRuler 1.0.2

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release May 2018
SPMSupports SPM

Maintained by Dan Jiang, Dan Jiang.



DTRuler 1.0.2

DTRuler

Swift Platform CocoaPods Carthage compatible

Introduction

Simple ruler input control.

Demo

Installation

Requirement

iOS 8.4+

CocoaPods

To install DTRuler add a dependency to your Podfile:

pod "DTRuler"

Carthage

To install DTRuler add a dependency to your Cartfile:

github "danjiang/DTRuler"
carthage update --platform ios

Usage

Import

import DTRuler

Use

// 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)
  }

}

Customize

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()