Home

Awesome

<p align="center"> <img src="images/logo.jpg"/> </p>

Build Status Version License Platform Swift

⚠️ To use with Swift 5.0 please ensure you are using >= 0.8.0 ⚠️

⚠️ To use with Swift 4.2 please ensure you are using >= 0.7.1 ⚠️

⚠️ To use with Swift 4.x please ensure you are using >= 0.6.1 ⚠️

⚠️ To use with Swift 3.x please ensure you are using >= 0.5.0 ⚠️

⚠️ To use with Swift 2.3 please ensure you are using == 0.4.1 ⚠️

Purpose

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.

NXDrawKit is a set of classes designed to use drawable view easily. This framework consists of 3 kinds of views.

Screenshot

<p align="center"> <img src="images/screenShot.gif" border="black"/> </p>

Installation

Accio/SwiftPM

You can use Accio or Swift Package Manager to install NXDrawKit by adding it to your Package.swift file:

.package(url: "https://github.com/Nicejinux/NXDrawKit", .branch("master"));

CocoaPods

You can use CocoaPods to install NXDrawKit by adding it to your Podfile:

platform :ios, '8.0'
use_frameworks!
pod 'NXDrawKit'

To get the full benefits import NXDrawKit wherever you import UIKit

import UIKit
import NXDrawKit

Carthage

Create a Cartfile that lists the framework and run carthage bootstrap. Follow the instructions to add $(SRCROOT)/Carthage/Build/iOS/NXDrawKit.framework to an iOS project.

github "nicejinux/NXDrawKit"

Manually

  1. Download and drop /NXDrawKit folder in your project.
  2. Congratulations!

Components

Canvas

- Delegate

Canvas will call the delegate when user draw or save image.

// optional
func canvas(canvas: Canvas, didUpdateDrawing drawing: Drawing, mergedImage image: UIImage?)
func canvas(canvas: Canvas, didSaveDrawing drawing: Drawing, mergedImage image: UIImage?)

// required
func brush() -> Brush?

- Model

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
}

- Public Methods

func update(backgroundImage: UIImage?)
func undo()
func redo()
func clear()
func save() 

Palette

- Delegate

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

- Public Method

func currentBrush() -> Brush

ToolBar

- Public Properties

var undoButton: UIButton?
var redoButton: UIButton?
var saveButton: UIButton?
var loadButton: UIButton?
var clearButton: UIButton?

UIImage Extension

public extension UIImage {
    @objc public func asPNGData() -> Data? {
        return self.pngData()
    }
    
    @objc public func asJPEGData(_ quality: CGFloat) -> Data? {
        return self.jpegData(compressionQuality: quality);
    }
    
    @objc public func asPNGImage() -> UIImage? {
        if let data = self.asPNGData() {
            return UIImage(data: data)
        }
        
        return nil
    }
    
    @objc public func asJPGImage(_ quality: CGFloat) -> UIImage? {
        if let data = self.asJPEGData(quality) {
            return UIImage(data: data)
        }
        
        return nil
    }
}

Version History

Will be improved

Author

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.

MIT License

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.