NXDrawKit is a simple and easy but useful drawing kit for iPhone

Related tags

Graphics NXDrawKit
Overview

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.

  • 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.

Screenshot

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.

  • Delegate provides user stroke image, background image and merged image.
  • User should provide the 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 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

  • User can set background image.
  • User can undo, redo or clear the Canvas. (Maximum history size is 50)
  • User can save current stroke and background internally, then Canvas calls didSaveDrawing: delegate
func update(backgroundImage: UIImage?)
func undo()
func redo()
func clear()
func save() 

Palette

  • Palette has 12 buttons for color, 3 buttons for alpha and 4 buttons for width of brush.
  • You can customize color, value of alpha and width of brush with delegate,
  • You can't customize number of buttons.

- Delegate

  • Palette will call the delegate when user clicks the color, alpha or width button.
  • You can customize the color, alpha or width with delegate. (all delegates are optional)
func didChangeBrushColor(color: UIColor)
func didChangeBrushAlpha(alpha: CGFloat)
func didChangeBrushWidth(width: CGFloat)
  • tag can be 1 ... 12
  • If you return nil, the color of tag will set with default color provided by NXDrawKit.
  • If you return clearColor, the color of tag will be Eraser.
func colorWithTag(tag: NSInteger) -> UIColor?
  • tag can be 1 ... 3
  • If you return -1, the alpha of tag will set with default alpha provided by NXDrawKit.
func alphaWithTag(tag: NSInteger) -> CGFloat
  • tag can be 1 ... 4
  • If you return -1, the width of tag will set with default width provided by NXDrawKit.
func widthWithTag(tag: NSInteger) -> CGFloat

- Public Method

func currentBrush() -> Brush

ToolBar

- Public Properties

  • All buttons are set with default values without #selector.
  • If you want to use buttons on the ToolBar, you have to add #selector for each buttons.
var undoButton: UIButton?
var redoButton: UIButton?
var saveButton: UIButton?
var loadButton: UIButton?
var clearButton: UIButton?

UIImage Extension

  • This extension can make you get PNG or JPEG format image directly for sharing or saving from what you draw.
  • All methods can return nil, so you should check before use whether it's nil or not.
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

  • 0.8.1
    • FIX: SPM issue
  • 0.8.0
    • UPDATE: Support Xcode10, Swift 5.0
  • 0.7.1
    • UPDATE: Support Xcode10, Swift 4.2
  • 0.6.1
    • UPDATE: Support Xcode9, Swift 4.0
  • 0.5.1
    • UPDATE: Support Xcode8, Swift 3.0
  • 0.4.1
    • UPDATE: Support Xcode8, Swift 2.3
  • 0.3.4
    • FIX: Removing background image issue
  • 0.3.0
    • ADD: Eraser added
  • 0.2.0
    • CHANGE: Data model renamed Paper to Drawing
  • 0.1.0
    • Release

Will be improved

  • Swift style code
  • There is no Eraser, so user can't erase stroke. - added v0.2.0
  • User can't remove background image after it's set.
  • Palette and ToolBar can't customize easily.

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.
Comments
  • Undo clears background image

    Undo clears background image

    When creating a Canvas with a background image with Canvas(backgroundImage: UIImage.init(named: "Image")!) calling undo wipes everything including the background image.

    The undo functionality should undo the first drawing but not clear the background image. It seems the first drawing and the setting of the image are merged into the first action.

    opened by waltermvp 8
  • The paper name is...

    The paper name is...

    "Canvas": https://en.wikipedia.org/wiki/Canvas

    What you call "canvas" is actually an "easel": https://en.wikipedia.org/wiki/Easel

    Cool project!

    opened by LeoNatan 6
  • Carthage Error

    Carthage Error

    *** No Cartfile.resolved found, updating dependencies *** Fetching NXDrawKit *** Checking out NXDrawKit at "0.5.0" *** xcodebuild output can be found in /var/folders/_c/3gsl_2314yb_xbhnhc1ld89h0000gn/T/carthage-xcodebuild.MndZdz.log Dependency "NXDrawKit" has no shared framework schemes

    cart file github "nicejinux/NXDrawKit" ~> 0.5.0

    carthage version 0.20.0

    xcode 8.2.1

    opened by vasiliilevkovskii 4
  • Does it handle Auto-Rotate

    Does it handle Auto-Rotate

    I'm looking into a lot of drawing kits and haven't found a single one yet, that handles auto-rotation. Would be amazing to see this working. Either by refitting it onto the screen, or just drawing it as if the view didn't rotate.

    opened by olbrichj 4
  • Keyboard style Palette?

    Keyboard style Palette?

    Is there an inbuilt way of creating the Palette as a keyboard style? Like the user would be able to dismiss the Palette after selecting the color and continue to draw on the canvas. Currently the Palette kind of takes about half of the screen, but with a keyboard style we can make the whole screen available to the user for drawing and create a better experience. I will try it in my code and submit a PR if you are ok with having a feature like this.

    question 
    opened by annjawn 3
  • Ability to update refresh-rate?

    Ability to update refresh-rate?

    The drawing currently works well, but is a little choppy unfortunately. It'd be nice if there was an option to set how frequently the active drawing gets updated, so that movement produces a more seamless stroke.

    question 
    opened by dafurman 1
  • undos and redos saved the Drawing with background  and stroke image that might caused a memory increase issue

    undos and redos saved the Drawing with background and stroke image that might caused a memory increase issue

    I noticed that the undo and redo arrays saved the background and stroke images. I tried to repeat to insert background images from album with a high quality , with Instruments, the memory quickly increase to 1GiB+.

    bug 
    opened by LuckinDog 2
Releases(0.8.0)
Owner
Nicejinux
Nicejinux
Drawing and Geometry made easy on iOS - now in Swift 3.0

InkKit Swift Support Swift 4.0 InkKit is Swift 4.0 by default, so to use that just include InkKit in your podfile: pod 'InkKit' Swift 3.2 In order to

Shaps 373 Dec 27, 2022
A simple, declarative, functional drawing framework, in Swift!

DePict - A simple, declarative, functional drawing framework. To produce a drawing, call the Draw function (just type Draw and let autocomplete do the

David Cairns 35 Sep 16, 2021
it's simple drawing app.

IOSObjC_KidsBoard The application is develop in Objective IOS. kids can draw whatever they want and also kids can save the drawing as well as undo era

Vnnovate Solutions Pvt Ltd 0 Oct 28, 2021
it's simple drawing app

IOSObjC_KidsBoard The application is develop in Objective IOS. kids can draw whatever they want and also kids can save the drawing as well as undo era

Jiten Engineer 0 Oct 28, 2021
A super easy way to check if the installed app has an update available. It is built with simplicity and customisability in mind and comes with pre-written tests.

UpdateAvailableKit This is UpdateAvailableKit: a super easy way to check if the installed app has an update available. It is built with simplicity and

Swapnanil Dhol 22 Jan 5, 2023
Powerful and easy-to-use vector graphics Swift library with SVG support

Macaw Powerful and easy-to-use vector graphics Swift library with SVG support We are a development agency building phenomenal apps. What is Macaw? Mac

Exyte 5.9k Jan 2, 2023
Crafter - Xcode project configuration CLI made easy.

How do you setup your Cocoa projects? Do you always set same warnings, clone configurations and do bunch of other stuff? Or maybe you work in a big co

Krzysztof Zabłocki 548 Nov 28, 2022
A simple, performant, and lightweight SVG parser

Key Features Parsing performance that meets or beats other popular SVG Frameworks A simple architecture, optimized for extension, flexibility and deve

Michael Choe 1.8k Dec 29, 2022
🎞 Powerful gradient animations made simple for iOS.

AnimatedGradientView is a UIView subclass which makes it simple to add animated gradients to your iOS app. It is written purely in Swift. Further docu

Ross Butler 431 Dec 12, 2022
A simple game application for iPad using SpriteKit, SKCropNode

Whack-a-Penguin A simple game application for iPad using SpriteKit, SKCropNode,

NIKOLAY NIKITIN 1 Sep 12, 2022
iOS utility classes for asynchronous rendering and display.

YYAsyncLayer iOS utility classes for asynchronous rendering and display. (It was used by YYText) Simple Usage @interface YYLabel : UIView @property NS

null 672 Dec 27, 2022
An iOS framework for easily adding drawings and text to images.

jot is an easy way to add touch-controlled drawings and text to images in your iOS app. What's jot for? Annotating Images jot is the easiest way to ad

IFTTT 1.8k Oct 28, 2022
Display and interact with SVG Images on iOS / OS X, using native rendering (CoreAnimation)

SVGKit SVGKit is a Cocoa framework for rendering SVG files natively: it's fast and powerful. Some additional info and links are on the wiki Versions:

null 4.3k Jan 3, 2023
Create gradients and blur gradients without a single line of code

EZYGradientView is a different and unique take on creating gradients and gradients with blur on the iOS platform. The default CAGradientLayer implemen

Shashank Pali 380 Dec 6, 2022
When you scan the clothing tag, a 3D character appears and informs you of the clothing information.

1. Introduction When you scan the clothing tag, a 3D character appears and tells you the information on the clothes. You can select necessary informat

kimniki 0 Dec 23, 2021
SVG parser and renderer written in SwiftUI

SVGView SVG parser written in SwiftUI We are a development agency building phenomenal apps. Overview The goal of this project is to bring the full pow

Exyte 269 Jan 4, 2023
A lightweight XMLParser for assembling and parsing XML values written for iOS 8+ in Swift 2.

Overview Description Requirements Installation Usage Author License Description XMLParser lets you convert a pure Swift dictionary into XML string and

Eugene Mozharovsky 75 Feb 2, 2022
3D Touch Application for Weighing Plums (and other small fruit!)

Plum-O-Meter ###3D Touch Application for Weighing Plums (and other small fruit!) Companion project to this blog post: http://flexmonkey.blogspot.co.uk

simon gladman 526 Sep 27, 2022
The application is develop in Objective IOS. kids can draw whatever they want and also kids can save the drawing as well as undo erase the drawing.

IOSObjC_KidsBoard The application is develop in Objective IOS. kids can draw whatever they want and also kids can save the drawing as well as undo era

Haresh 0 Oct 28, 2021
A Lightweight But Powerful Color Kit (Swift)

BCColor A lightweight but powerful color kit (Swift) Features Pick Colors From Image Generate Monochrome Image Support Hex Color Style Lighten / Darke

Xiaobo Zhang 418 Nov 25, 2022