Drawing and Geometry made easy on iOS - now in Swift 3.0

Overview

InkKit

Version License Language Platform

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 use InkKit in a Swift 3.2/3.0 project, ensure you point to the 2.1.0 tag.

pod 'InkKit', '2.1.0'

Swift 2.3

In order to use InkKit in a Swift 2.3 project, ensure you point to the swift2.3 branch.

pod 'InkKit', :git => 'https://github.com/shaps80/InkKit/', :branch => 'swift2.3'

Swift 2.2

If you still require Swift 2.2, point your version as such: pod 'InkKit', '1.3.1'

Example Code

Everything you see here, was code-drawn with InkKit! In fact, other than some CGRect instances, this is ALL the code required to draw the image you see on the right ;)

Drawing made simple! InkKit In Action
Lets draw the screen on the right.
Draw.fillRect(bgFrame, color: UIColor(hex: "1c3d64"))
let grid = Grid(colCount: 6, rowCount: 9, bounds: gridFrame)
let path = grid.path(includeComponents: [.Columns, .Rows])

Draw.strokePath(path, startColor: UIColor(white: 1, alpha: 0.15), endColor: UIColor(white: 1, alpha: 0.05), angleInDegrees: 90)

let rect = grid.boundsForRange(sourceColumn: 1, sourceRow: 1, destinationColumn: 4, destinationRow: 6)

drawCell(rect, title: "4x6", includeBorder: true, includeShadow: true)

Draw.addShadow(.Outer, path: UIBezierPath(rect: barFrame), color: UIColor(white: 0, alpha: 0.4), radius: 5, offset: CGSize(width: 0, height: 1))

Draw.fillRect(barFrame, color: UIColor(hex: "ff0083"))

let (_, navFrame) = barFrame.divide(20, fromEdge: .MinYEdge) "InkKit".drawAlignedTo(navFrame, attributes: [ NSForegroundColorAttributeName: Color.whiteColor(), NSFontAttributeName: UIFont(name: "Avenir-Book", size: 20)! ])

backIndicatorImage().drawAtPoint(CGPoint(x: 22, y: 30))

Change Log

v2.0.0

Note: Since this is a Swift 3 release, I decided to also clean up the API and remove all deprecation warnings. InkKit 2.0 should be considered a new API.

  • Swift 3.0 Support
  • Updated API to support Swift 3.0 guidelines
  • Shear Transforms
  • Perspective Transforms
  • Radians from Degrees function (and inverse)
  • Corner Radius with Concave, Convex and Line support
  • New Color value-type

v1.3.1

  • OSX Support
  • OSX Demo Project now included
  • Table renamed to Grid
  • Table renamed to GridComponents
  • Added convenience methods for working with paths

v1.2.0

  • Shadows
  • Borders
  • Tables

v1.1.0

  • Images
  • Strings

v1.0

  • Fills
  • Strokes
  • Geometry

API

InkKit provides many useful convenience methods for drawing and geometry calculations. Its also cross platform working across iOS & MacOS

Core

If the convenience methods below don't solve your needs, you can start by using the new methods added directly to CGContext itself:

func draw(inRect:attributes:drawing:)

Which would look like this in usage:

CGContext.current?.draw(inRect: rect, drawing: { (context, rect, attributes) in
  Color.redColor.setFill()
  UIRectFill(rect)
})

This basically wraps getting the context, setting up its frame and save/restore calls. If you provide the additional DrawingAttributes block, it will also pre-configure your context with those options for you.

Grid

init(colCount:rowCount:bounds:)
func positionForCell(atIndex:) -> (col: Int, row: Int)
func boundsForCell(atIndex:) -> CGRect
func boundsForRange(sourceColumn:sourceRow:destinationColumn:destinationRow:) -> CGRect
func boundsForCell(col:row:) -> CGRect
func enumerateCells(enumerator:(index:col:row:bounds:) -> Void)

A Grid is a really great way for laying out your drawing without having to think about placement, rect translations, etc...

I use them often for layout only, but sometimes its useful to be able to render them as well (like in the included demo).

// components is a bitmask [ .Outline, .Rows, .Columns ]
func stroke(components:attributes:)

Borders & Shadows

Supports .Outer, .Inner and .Center borders, as well as .Outer and .Inner shadows.

static func addBorder(type:path:attributes:)
static func addShadow(type:path:color:radius:offset:)

Strokes

static func strokeLine(startPoint:endPoint:startColor:endColor:angleInDegrees:attributes:)
static func strokeLine(startPoint:endPoint:color:attributes:)
static func strokePath(path:startColor:endColor:angleInDegrees:attributes:)

Fills

static func fillPath(path:startColor:endColor:angleInDegrees:attributes:)

Geometry

Many of the drawing methods use the geometry additions below, but they can also be useful for your own projects:

func divide(atDelta:fromEdge:margin:) -> (slice, remainder)
func insetBy(edgeInsets:) -> CGRect
mutating func insetInPlace(edgeInsets:)
func alignedTo(rect:horizontal:vertical:) -> CGRect
func scaledTo(rect:scaleMode:) -> CGRect

func gradientPoints(forAngleInDegrees:) -> (start, end)
func scaledTo(size:scaleMode:) -> CGSize

func reversibleRect(fromPoint:toPoint:) -> CGRect

Images

There are also additional draw methods for images:

func drawAlignedTo(rect:horizontal:vertical:blendMode:alpha:)
func drawScaledTo(rect:scaleMode:blendMode:alpha:)

static func circle(radius:attributes:) -> Image
static func draw(width:height:scale:attributes:drawing:) -> Image
static func draw(size:scale:attributes:drawing:) -> Image

Strings

Finally, we even have some easy draw methods for strings:

func drawAlignedTo(rect:horizontal:vertical:attributes:constrainedSize:)
func sizeWithAttributes(attributes:constrainedSize:) -> CGSize
func drawAtPoint(point:attributes:)
func drawInRect(rect:withAttributes)

Demo

To try it out yourself, download the source and run the included demo project.

Platforms and Versions

InkKit is supported on the following platforms:

  • iOS 8.0 and greater
  • OSX 10.11 and greater

Installation

InkKit is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'InkKit'

Alternatively you can simply drag the files into your iOS or OSX project.

Author

@shaps

License

InkKit is available under the MIT license. See the LICENSE file for more info.

You might also like...
An iOS framework for easily adding drawings and text to images.
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

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:

Conical (angular) gradient for iOS written in Swift
Conical (angular) gradient for iOS written in Swift

AEConicalGradient Conical (angular) gradient in Swift I hope that somebody will find this useful. And nice. Usage AEConicalGradient is a minion which

A simple, performant, and lightweight SVG parser
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

Create gradients and blur gradients without a single line of code
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

When you scan the clothing tag, a 3D character appears and informs you of the clothing information.
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

SVG parser and renderer written in SwiftUI
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

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

The code for my CoreGraphics+CoreAnimation talk, held during the 2012 iOS Game Design Seminar at the Technical University Munich.

PKCoreTechniques ======= Core Techniques is the result of a presentation I held at the Technical University of Munich during the 'iOS Game Design Semi

Comments
  • Minor Swift 2.3 correction

    Minor Swift 2.3 correction

    Sorry I can't find a way to point to the 1.3.1 tag for my pull request. https://github.com/shaps80/InkKit/tree/1.3.1 is Swift 2.2 This PR update it to Swift 2.3

    opened by huguesbr 4
  • Migrate InkKit to use UIGraphicsRenderer

    Migrate InkKit to use UIGraphicsRenderer

    This is currently in progress and will be a back-port of UIGraphicsRenderer so that iOS 8+ can be supported, as well as support for OSX. This will also be Swift 3 only!

    opened by shaps80 0
Releases(4.0.1)
  • 4.0.1(Mar 25, 2018)

    ‣ Swift 3.0 Support ‣ Updated API to support Swift 3.0 guidelines ‣ Shear Transforms ‣ Perspective Transforms ‣ Radians from Degrees function (and inverse) ‣ Corner Radius with Concave, Convex and Line support ‣ New Color value-type

    Note: Since this is a Swift 3 release, I decided to also clean up the API and remove all deprecation warnings. InkKit 2.0 should be considered a new API.

    Source code(tar.gz)
    Source code(zip)
Owner
Shaps
Engineer @thirdfort and @EverythingSet ● Open source @SwiftUI-Plus ● I love to build tools for the world
Shaps
NXDrawKit is a simple and easy but useful drawing kit for iPhone

⚠️ 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

Nicejinux 1.3k Dec 31, 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
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
🎞 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 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
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
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