Skip to content
/ Fader Public

A graphical user interface for changing variables in Swift.

License

Notifications You must be signed in to change notification settings

ryohey/Fader

Repository files navigation

Fader

CI Status Version License Platform

many faders

video

Fader is a lightweight controller library for Swift heavily inspired by dat.gui.

Code Example

let fader = Fader(frame: .zero)

fader.add(target: particle,
          keyPath: \SCNParticleSystem.birthRate,
          minValue: 0.0,
          maxValue: 1000.0)

By new KeyPath syntax of Swift 4, we can describe it type-safely and shortly.

Usage

image

  1. Add Fader view to your screen
  2. Add x, y, width constraints
  3. Add codes to specify properties to modify

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Installation

Fader is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'Fader'

KeyPath API

Since pure swift class can not get the name from KeyPath, use the label parameter.

Number

fader.add(target: car,
          keyPath: \Car.speed,
          minValue: 0.0,
          maxValue: 120.0)

Boolean

fader.add(target: door,
          keyPath: \Door.isClosed)

String

fader.add(target: label,
          keyPath: \UILabel.text)

Callback API

Specify initialValue to set the initial value with Callback API.

Number

fader.add(label: "strength", minValue: 0.0, maxValue: 100) { (value: Double) in
    self.attackStrength = value
}

Boolean

fader.add(label: "on off") { (isOn: Bool) in
    self.switch.isOn = isOn
}

String

fader.add(label: "name") { (str: String?) in
    self.nameLabel.text = str
}

Author

ryohey, [email protected]

License

Fader is available under the MIT license. See the LICENSE file for more info.