The TouchDraw
module allows you to use the TouchDrawView
class. This is a subclass of UIView
which allows you to draw pictures with your finger.
The easiest way to include TouchDraw
is by using CocoaPods
and adding the following to your Podfile
.
use_frameworks!
pod 'TouchDraw', '~> 2.0'
If you're not using CocoaPods, you can add the TouchDrawView.swift
file to your project.
You can either programmatically add the TouchDrawView
or add it using storyboards.
If using storyboards, you must add a UIView
to your storyboard. Give it the TouchDrawView
class, and TouchDraw
module.
If programmatically adding the view, you can use the init(frame: CGRect)
method to create a new instance of TouchDrawView
. You must make sure to write import TouchDraw
at the top of the class.
When customizing the TouchDrawView
you can setting its delegate
. The container can conform to parts of TouchDrawViewDelegate
, which has the following functions:
func undoEnabled() -> Void {
// triggered when undo is enabled
// (only if it was previously disabled)
}
func undoDisabled() -> Void {
// triggered when undo is disabled
// (only if it previously enabled)
}
func redoEnabled() -> Void {
// triggered when redo is enabled
// (only if it was previously disabled)
}
func redoDisabled() -> Void {
// triggered when redo is disabled
// (only if it previously enabled)
}
func clearEnabled() -> Void {
// triggered when clear is enabled
// (only if it was previously disabled)
}
func clearDisabled() -> Void {
// triggered when clear is disabled
// (only if it previously enabled)
}
The TouchDrawView
exposes the following methods:
exportDrawing() -> UIImage
- Exports a UIImage version of the drawing.
clearDrawing()
- Clears the TouchDrawView.
undo()
- Undo the last stroke.
redo()
- Redo what was undone.
setColor(color: UIColor)
- Sets the color of future strokes.
setWidth(width: CGFloat)
- Sets the width of future strokes.
importStack(stack: [Stroke])
- Set the
TouchDrawView
to have certain strokes (usually will be used in conjunction withexportStack()
.
- Set the
exportStack() -> [Stroke]
- Exports the strokes from a
TouchDrawView
so they can be imported later.
- Exports the strokes from a
If you'd like to see this library in action, you can download the entire repository and open Demo/TouchDrawDemo.xcworkspace.
Demo/TouchDrawDemo/ViewController.swift is where most of its functionality is demonstrated.
If you'd like to see additional functionality, feel free to open up a new issue or submit a pull request if you'd like to author it yourself.
This package has the MIT license, which can be found here: LICENSE.