{"id":1172,"url":"https://github.com/Nicejinux/NXDrawKit","last_synced_at":"2025-07-30T20:32:44.061Z","repository":{"id":56488463,"uuid":"64145955","full_name":"Nicejinux/NXDrawKit","owner":"Nicejinux","description":"NXDrawKit is a simple and easy but useful drawing kit for iPhone","archived":false,"fork":false,"pushed_at":"2020-11-04T15:13:38.000Z","size":1296,"stargazers_count":1341,"open_issues_count":2,"forks_count":107,"subscribers_count":30,"default_branch":"master","last_synced_at":"2024-11-14T01:05:23.297Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Nicejinux.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-07-25T15:24:46.000Z","updated_at":"2024-11-08T16:12:10.000Z","dependencies_parsed_at":"2022-08-15T19:40:38.772Z","dependency_job_id":null,"html_url":"https://github.com/Nicejinux/NXDrawKit","commit_stats":null,"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nicejinux%2FNXDrawKit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nicejinux%2FNXDrawKit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nicejinux%2FNXDrawKit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nicejinux%2FNXDrawKit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Nicejinux","download_url":"https://codeload.github.com/Nicejinux/NXDrawKit/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228187549,"owners_count":17882324,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-01-05T20:15:40.483Z","updated_at":"2024-12-04T20:31:03.536Z","avatar_url":"https://github.com/Nicejinux.png","language":"Swift","funding_links":[],"categories":["Graphics","Swift","UI"],"sub_categories":["Getting Started","Other free courses","Linter"],"readme":"\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"images/logo.jpg\"/\u003e\n\u003c/p\u003e\n\n\n[![Build Status](https://travis-ci.org/Nicejinux/NXDrawKit.svg?branch=master)](https://travis-ci.org/Nicejinux/NXDrawKit)\n[![Version](https://img.shields.io/cocoapods/v/NXDrawKit.svg?style=flat)](http://cocoapods.org/pods/NXDrawKit)\n[![License](https://img.shields.io/badge/license-MIT-yellow.svg)](http://cocoapods.org/pods/NXDrawKit)\n[![Platform](https://img.shields.io/cocoapods/p/NXDrawKit.svg?style=flat)](http://cocoapods.org/pods/NXDrawKit)\n[![Swift](https://img.shields.io/badge/Swift-5.0-green.svg)](http://cocoapods.org/pods/NXDrawKit)\n\n#### ⚠️ **To use with Swift 5.0 please ensure you are using \u003e= 0.8.0** ⚠️ \n#### ⚠️ **To use with Swift 4.2 please ensure you are using \u003e= 0.7.1** ⚠️ \n#### ⚠️ **To use with Swift 4.x please ensure you are using \u003e= 0.6.1** ⚠️ \n#### ⚠️ **To use with Swift 3.x please ensure you are using \u003e= 0.5.0** ⚠️ \n#### ⚠️ **To use with Swift 2.3 please ensure you are using == 0.4.1** ⚠️ \n  \n  \n# Purpose\nIt's just started for my personal app for iPhone.\nThough, it can not be customized as much as you want, you can use [Smooth Freehand Drawing View](http://code.tutsplus.com/tutorials/ios-sdk_freehand-drawing--mobile-13164) easily.\nI made `Palette` and `ToolBar` for using `Canvas`, so **you don't have to use** `Palette` and `ToolBar`.\n\n**NXDrawKit** is a set of classes designed to use drawable view easily. \nThis framework consists of 3 kinds of views.\n - `Canvas` providing redo, undo, clear, save and load image is a view  for drawing.\n - `Palette` calls delegate with color, alpha and width when user clicks the button.\n - `ToolBar` represents the features of `Canvas`, and can show the status of `Canvas`.\n\n\n\n# Screenshot\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"images/screenShot.gif\" border=\"black\"/\u003e\n\u003c/p\u003e\n\n\n\n# Installation\n\n## Accio/SwiftPM\nYou can use [Accio](https://github.com/JamitLabs/Accio) or [Swift Package Manager](https://github.com/apple/swift-package-manager) to install `NXDrawKit` by adding it to your `Package.swift` file:\n\n```swift\n.package(url: \"https://github.com/Nicejinux/NXDrawKit\", .branch(\"master\"));\n```\n\n## CocoaPods\nYou can use [CocoaPods](http://cocoapods.org/) to install `NXDrawKit` by adding it to your `Podfile`:\n\n```ruby\nplatform :ios, '8.0'\nuse_frameworks!\npod 'NXDrawKit'\n```\n\nTo get the full benefits import `NXDrawKit` wherever you import UIKit\n\n``` swift\nimport UIKit\nimport NXDrawKit\n```\n## Carthage\nCreate a `Cartfile` that lists the framework and run `carthage bootstrap`. Follow the [instructions](https://github.com/Carthage/Carthage#if-youre-building-for-ios) to add `$(SRCROOT)/Carthage/Build/iOS/NXDrawKit.framework` to an iOS project.\n\n```\ngithub \"nicejinux/NXDrawKit\"\n```\n## Manually\n1. Download and drop ```/NXDrawKit``` folder in your project.  \n2. Congratulations!  \n\n# Components\n## Canvas \n### - Delegate\n`Canvas` will call the delegate when user draw or save image.  \n- Delegate provides user stroke image, background image and merged image. \n- User should provide the `Brush` to `Canvas` for drawing.\n\n```swift\n// optional\nfunc canvas(canvas: Canvas, didUpdateDrawing drawing: Drawing, mergedImage image: UIImage?)\nfunc canvas(canvas: Canvas, didSaveDrawing drawing: Drawing, mergedImage image: UIImage?)\n\n// required\nfunc brush() -\u003e Brush?\n```\n\n### - Model\n\n```swift\npublic class Drawing: NSObject {\n    public var stroke: UIImage?\n    public var background: UIImage?\n    \n    public init(stroke: UIImage? = nil, background: UIImage? = nil) {\n        self.stroke = stroke\n        self.background = background\n    }\n}\n\npublic class Brush: NSObject {\n    public var color: UIColor = UIColor.blackColor()\n    public var width: CGFloat = 5.0\n    public var alpha: CGFloat = 1.0\n}\n```\n\n\n### - Public Methods\n - User can set background image.\n - User can ***undo***, ***redo*** or ***clear*** the `Canvas`. (**Maximum history size is 50**)\n - User can ***save*** current stroke and background internally, then `Canvas` calls ***didSaveDrawing:*** delegate\n\n```swift\nfunc update(backgroundImage: UIImage?)\nfunc undo()\nfunc redo()\nfunc clear()\nfunc save() \n```\n\n## Palette \n - `Palette` has 12 buttons for color, 3 buttons for alpha and 4 buttons for width of brush.\n - **You can** customize color, value of alpha and width of brush with delegate, \n - **You can't** customize number of buttons.\n\n### - Delegate\n - `Palette` will call the delegate when user clicks the color, alpha or width button.\n - You can customize the color, alpha or width with delegate. (**all delegates are optional**)\n\n```swift\nfunc didChangeBrushColor(color: UIColor)\nfunc didChangeBrushAlpha(alpha: CGFloat)\nfunc didChangeBrushWidth(width: CGFloat)\n```\n\n - ***tag*** can be ***1 ... 12*** \n - If you return ***nil***, the color of tag will set with default color provided by **NXDrawKit**.\n - If you return ***clearColor***, the color of tag will be Eraser.\n\n```swift\nfunc colorWithTag(tag: NSInteger) -\u003e UIColor?\n```\n\n - ***tag*** can be ***1 ... 3***\n - If you return ***-1***, the alpha of tag will set with default alpha provided by **NXDrawKit**.\n\n```swift\nfunc alphaWithTag(tag: NSInteger) -\u003e CGFloat\n```\n\n - ***tag*** can be ***1 ... 4***\n - If you return ***-1***, the width of tag will set with default width provided by **NXDrawKit**.\n\n```swift\nfunc widthWithTag(tag: NSInteger) -\u003e CGFloat\n\n```\n\n\n### - Public Method\n\n```swift\nfunc currentBrush() -\u003e Brush\n```\n\n## ToolBar\n### - Public Properties\n - All buttons are set with default values without **#selector**.\n - If you want to use buttons on the `ToolBar`, you have to add **#selector** for each buttons.\n```swift\nvar undoButton: UIButton?\nvar redoButton: UIButton?\nvar saveButton: UIButton?\nvar loadButton: UIButton?\nvar clearButton: UIButton?\n```\n\n## UIImage Extension\n  - This extension can make you get **PNG** or **JPEG** format image directly for sharing or saving from what you draw.\n  - All methods can return ***nil***, so you should check before use whether it's ***nil*** or not.\n```swift\npublic extension UIImage {\n    @objc public func asPNGData() -\u003e Data? {\n        return self.pngData()\n    }\n    \n    @objc public func asJPEGData(_ quality: CGFloat) -\u003e Data? {\n        return self.jpegData(compressionQuality: quality);\n    }\n    \n    @objc public func asPNGImage() -\u003e UIImage? {\n        if let data = self.asPNGData() {\n            return UIImage(data: data)\n        }\n        \n        return nil\n    }\n    \n    @objc public func asJPGImage(_ quality: CGFloat) -\u003e UIImage? {\n        if let data = self.asJPEGData(quality) {\n            return UIImage(data: data)\n        }\n        \n        return nil\n    }\n}\n```\n\n\n\n# Version History\n* 0.8.1\n    * FIX: SPM issue\n* 0.8.0\n    * UPDATE: Support Xcode10, Swift 5.0\n* 0.7.1\n    * UPDATE: Support Xcode10, Swift 4.2\n* 0.6.1\n    * UPDATE: Support Xcode9, Swift 4.0\n* 0.5.1\n    * UPDATE: Support Xcode8, Swift 3.0\n* 0.4.1\n    * UPDATE: Support Xcode8, Swift 2.3\n* 0.3.4\n    * FIX: Removing background image issue \n* 0.3.0\n    * ADD: Eraser added\n* 0.2.0\n    * CHANGE: Data model renamed `Paper` to `Drawing`\n* 0.1.0\n    * Release\n\n## Will be improved\n- [x] Swift style code\n- [x] There is no Eraser, so user can't erase stroke. - added v0.2.0\n- [ ] User can't remove background image after it's set.\n- [ ] `Palette` and `ToolBar` can't customize easily.\n\n\n# Author\nThis is [Jinwook Jeon](http://Nicejinux.NET). \nI've been working as an iOS developer in Korea. \nThis is my first Swift project, so there can be lots of weird things in this framework.\nI'm waiting for your comments, suggestions, fixes, everything what you want to say.\nFeel free to contact me.\n\n - email : nicejinux@gmail.com\n - facebook : http://facebook.com/Nicejinux\n - homepage : http://Nicejinux.NET\n\n\n# MIT License\n\n\tCopyright (c) 2016 Jinwook Jeon. All rights reserved.\n\n\tPermission is hereby granted, free of charge, to any person obtaining a\n\tcopy of this software and associated documentation files (the \"Software\"),\n\tto deal in the Software without restriction, including\n\twithout limitation the rights to use, copy, modify, merge, publish,\n\tdistribute, sublicense, and/or sell copies of the Software, and to\n\tpermit persons to whom the Software is furnished to do so, subject to\n\tthe following conditions:\n\n\tThe above copyright notice and this permission notice shall be included\n\tin all copies or substantial portions of the Software.\n\n\tTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS\n\tOR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n\tMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\n\tIN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\n\tCLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\n\tTORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\n\tSOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n\t\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FNicejinux%2FNXDrawKit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FNicejinux%2FNXDrawKit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FNicejinux%2FNXDrawKit/lists"}