Skip to content

A UIControl subclass for two-dimension directional input

License

Notifications You must be signed in to change notification settings

gabrieloc/PadControl

Repository files navigation

PadControl

Carthage compatible

A UIControl subclass for two-dimension directional input. Supports customization of color and other cosmetic attributes. To use with Carthage, add the following to your Cartfile:

github "gabrieloc/PadControl"

If you prefer not using Carthage, simply copy PadControl.swift into your project.

Example Usage

Create an instance of PadControl by providing direction information (PadDirections). To create a unidirectional pad in your View Controller:

override func viewDidLoad() {
	super.viewDidLoad

	let pad = PadControl(directions: [.up])
	pad.addTarget(self, action: #selector(padUpdated), for: .valueChanged)
	view.addSubview(pad)
}

@objc func padUpdated(sender: PadControl) {
	let value = sender.value(forDirection: .up)
	// value is a a Double from 0 - 1
}

Passing different directions allows for a variety of uni or bidirectional inputs to be created. For example: X axis Y axis Both axis corner

To view all of these examples, refer to the app target in the main .xcodeproj entitled PadControl Example.

FYI

PadControl is used by SCARAB, a free quadcopter controller for iOS. If you are interested in building quadcopter software, SCARAB is also powered by QuadKit, a framework for communicating with generic quadcopters.

About

A UIControl subclass for two-dimension directional input

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published