It's just started for my personal app for iPhone. Though, it can not be customized as much as you want, you can use Smooth Freehand Drawing View easily. I made Palette
and ToolBar
for using Canvas
, so you don't have to use Palette
and ToolBar
.
NXDrawKitis a set of classes designed to use drawable view easily. This framework consists of 3 kinds of views.
Canvas
providing redo, undo, clear, save and load image is a view for drawing. Palette
calls delegate with color, alpha and width when user clicks the button. ToolBar
represents the features of Canvas
, and can show the status of Canvas
.
pod 'NXDrawKit'
github "nicejinux/NXDrawKit"
Canvas
will call the delegate when user draw or save image.
Brush
to Canvas
for drawing. // optional func canvas(canvas: Canvas, didUpdateDrawing drawing: Drawing, mergedImage image: UIImage?) func canvas(canvas: Canvas, didSaveDrawing drawing: Drawing, mergedImage image: UIImage?) // required func currentBrush() -> Brush?
public class Drawing: NSObject { public var stroke: UIImage? public var background: UIImage? public init(stroke: UIImage? = nil, background: UIImage? = nil) { self.stroke = stroke self.background = background } } public class Brush: NSObject { public var color: UIColor = UIColor.blackColor() public var width: CGFloat = 5.0 public var alpha: CGFloat = 1.0 }
Canvas
. ( Maximum history size is 50 ) Canvas
calls didSavePaper: delegate func update(backgroundImage: UIImage?) func undo() func redo() func clear() func save()
Palette
has 12 buttons for color, 3 buttons for alpha and 4 buttons for width of brush. Palette
will call the delegate when user clicks the color, alpha or width button. func didChangeBrushColor(color: UIColor) func didChangeBrushAlpha(alpha: CGFloat) func didChangeBrushWidth(width: CGFloat)
func colorWithTag(tag: NSInteger) -> UIColor?
func alphaWithTag(tag: NSInteger) -> CGFloat
func widthWithTag(tag: NSInteger) -> CGFloat
func currentBrush() -> Brush
ToolBar
, you have to add #selector for each buttons. var undoButton: UIButton? var redoButton: UIButton? var saveButton: UIButton? var loadButton: UIButton? var clearButton: UIButton?
Palette
and ToolBar
can't customize easily. This is Jinwook Jeon . I've been working as an iOS developer in Korea. This is my first Swift project, so there can be lots of weird things in this framework. I'm waiting for your comments, suggestions, fixes, everything what you want to say. Feel free to contact me.
Copyright (c) 2016 Jinwook Jeon. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.