• Stars
    star
    373
  • Rank 114,600 (Top 3 %)
  • Language
    Swift
  • License
    MIT License
  • Created over 8 years ago
  • Updated about 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

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.

More Repositories

1

Peek

All new design. Inspect your iOS application at runtime.
Swift
2,601
star
2

SwiftUIBackports

A collection of SwiftUI backports for iOS, macOS, tvOS and watchOS
Swift
940
star
3

iMessageStyleReveal

Adds iMessage style timestamp support. Written in Swift!
Swift
147
star
4

MarkdownText

A native SwiftUI view for rendering Markdown text in an iOS or macOS app
Swift
142
star
5

GraphicsRenderer

A drop-in UIGraphicsRenderer port -- CrossPlatform, Swift 4, Image & PDF
Swift
109
star
6

Warrant

Data validation made easy. In code and from Interface Builder.
Swift
54
star
7

Stack

A Type-Safe, Thread-Safe-ish approach to CoreData in Swift
Swift
48
star
8

SwiftUIPlus

SwiftUI additions and helpers that are missing from the official implementation.
Swift
24
star
9

Color

A Swifty type-safe abstraction around color models
Objective-C
23
star
10

Feedback

Familiar, easy state-driven haptics, audio and more
Swift
22
star
11

ColumnView

A column-view navigation controller that behaves similarly to Files and Finder
Swift
21
star
12

Logging

Apple's SwiftLog + OSLog style StringInterpolation
Swift
16
star
13

Objective-C-Style-Guide

Objective-C Style Guide
15
star
14

SwiftUIBackportsDemo

A collection of Demo's for the SwiftUI Backports.
Swift
15
star
15

SwiftBackports

A collection of Swift backports for earlier versions of iOS, macOS, tvOS and watchOS
Swift
13
star
16

Abracadabra

A truly plug 'n' play solution for securing your code.
Objective-C
12
star
17

Snaply

Drop-in snapping behaviour for any scroll/collection/table/view using arbitrary points!
Swift
9
star
18

CornerMasking

SPXMasking is category on CALayer that allows you to specify different a corner radius for each corner of a CALayer.
Objective-C
8
star
19

MarkdownTextDemo

A demo app for showcasing the MarkdownText library.
Swift
7
star
20

SVGRenderer

An SVG renderer using the familiar GraphicsRenderer API.
Swift
6
star
21

ActivityView

Moved to SwiftUI-Plus/ActivityView
5
star
22

Storage

Moved to SwiftUI-Plus/DefaultStorage
5
star
23

Media

Moved to SwiftUI-Plus/Media
5
star
24

ghost-app-extract

Allows you to create better excerpt's in your Ghost blog posts.
JavaScript
4
star
25

AppManifest

Swift
4
star
26

SwiftLayout

A Swift library for programmatically dealing with AutoLayout
Swift
4
star
27

FlowLayout-Demo

A high-performance flow layout that provides global headers, footers, section backgrounds and various configurations.
Swift
4
star
28

Endpoints

A generic Swift networking library inspired by SwiftUI APIs
Swift
4
star
29

Analytics

Swift
3
star
30

PhotoLibrary

Photo library picker for iOS
Swift
2
star
31

primo

The first script to install a newly installed Mac! This will install common terminal utilities & applications.
Shell
2
star
32

Whos-Who

Who's Who sample code for job interview.
Objective-C
2
star
33

SPXLayout

AutoLayout the programmatic way
Objective-C
2
star
34

SPXSubscripting

This is a library for adding subscripting support to various Foundation classes. It also adds some interesting solutions to working with NSString's, NSAttributedString's and their attributes.
Objective-C
2
star
35

SPXDataSources

DataSource implementations for UITableView and UICollection, plus more...
Objective-C
2
star
36

Populate

Data providers for populating your data views.
Swift
2
star
37

bash

Various bash scripts I've written to simply my development and sometimes just to make me smile.
Shell
2
star
38

DownloadService

A Swift service for handling downloads and their associated resources.
Swift
1
star
39

SwiftHelpDemo

A demo project for showcasing SwiftHelp
Swift
1
star
40

SwiftHelp

A SwiftUI library for building interactive help systems in your apps
Swift
1
star
41

Development-Environment

All files, settings and configurations I use for my Development Environment's
1
star
42

FlowLayout

A high-performance flow layout that provides global headers, footers, section backgrounds and various configurations.
Swift
1
star
43

SPXCacheManager

A highly configurable and reusable library for handling caching in your iOS apps. Not only for images!!
Objective-C
1
star
44

SPXKeychain

My iOS Keychain Wrapper
Objective-C
1
star
45

PGTest-XCTest

Swift
1
star
46

ScaledMetric

A SwiftUI dynamic property wrapper (a back-port) that scales a numeric value. iOS, macOS, tvOS, watchOS
Swift
1
star
47

Snippex

My own personal library of reusable code that compiles and standardises some classes across iOS and OSX.
Objective-C
1
star
48

CellProvider

A generic cell provider implementation in Swift
Shell
1
star