This is an original fork from Awalz's SwiftyDraw repository.
SwiftyDraw is a simple, lightweight drawing framework written in Swift. SwiftyDraw is built using Core Gaphics and is very easy to implement.
- iOS 9.1+
- Swift 4
SwiftyDraw is available under the BSD license. See the LICENSE file for more info.
SwiftyDraw is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'SwiftyDraw', :git => 'https://github.com/LinusGeffarth/SwiftyDraw.git'
Simply copy the contents of the Source folder into your project.
Using SwiftyDraw is very simple:
Simply create a SwiftyDrawView and add it to your View Controller:
let drawView = SwiftyDrawView(frame: self.view.frame)
self.view.addSubview(drawView)
By default, the view will automatically respond to touch gestures and begin drawing. The default color is black.
To disable drawing, simply set the drawingEnabled
property to false:
drawView.drawingEnabled = false
The color of a line stoke can be changed by adjusting the lineColor
property. SwiftyDraw accepts any UIColor:
drawView.lineColor = UIColor.red
or
drawView.lineColor = UIColor(colorLiteralRed: 0.75, green: 0.50, blue: 0.88, alpha: 1.0)
The with of a line stroke can be changed by adjusting the lineWidth
property. SwiftyDraw accepts any positive CGFloat:
drawView.lineWidth = CGFloat(5.0)
The opacity of a line stoke can be changed by adjusting the lineOpacity
property. SwiftyDraw accepts a CGFloat between 0. and 1.0:
drawView.lineOpacity = CGFloat(0.5)
If you wish to clear the entire canvas, simply call the clear
function:
drawView.clear()
drawView.undo()
...and redo:
drawView.redo()
SwiftyDraw has delegate functions to notify you when a user is interacting with a SwiftDrawView. To access these delegate methods, simply add your View Controller as the SwiftyDrawViewDelegate
:
class ViewController: UIViewController, SwiftyDrawViewDelegate
/// SwiftyDrawViewDelegate called when a touch gesture should begin on the SwiftyDrawView using given touch type
func swiftyDraw(shouldBeginDrawingIn drawingView: SwiftyDrawView, using touch: UITouch) -> Bool
/// SwiftyDrawViewDelegate called when a touch gesture begins on the SwiftyDrawView.
func swiftyDraw(didBeginDrawingIn drawingView: SwiftyDrawView, using touch: UITouch)
/// SwiftyDrawViewDelegate called when touch gestures continue on the SwiftyDrawView.
func swiftyDraw(isDrawingIn drawingView: SwiftyDrawView, using touch: UITouch)
/// SwiftyDrawViewDelegate called when touches gestures finish on the SwiftyDrawView.
swiftyDraw(didFinishDrawingIn drawingView: SwiftyDrawView, using touch: UITouch)
/// SwiftyDrawViewDelegate called when there is an issue registering touch gestures on the SwiftyDrawView.
func swiftyDraw(didCancelDrawingIn drawingView: SwiftyDrawView, using touch: UITouch)
If you would like to propose any enhancements, bug fixes, etc., feel free to create a pull request or an issue respectively.
If you have any questions, or just want to say hi, reach out to me via Twitter, or email.