Skip to content

Instantly share code, notes, and snippets.

@mkj-is
Last active March 30, 2016 15:18
Show Gist options
  • Save mkj-is/f2b24b9a94316c8db958b87d4b0285c5 to your computer and use it in GitHub Desktop.
Save mkj-is/f2b24b9a94316c8db958b87d4b0285c5 to your computer and use it in GitHub Desktop.
PaintCode experiments
//
// ActivityIndicatorStyleKit.swift
//
//
// Created by Matěj Kašpar Jirásek on 30/03/16.
// Copyright (c) 2016 Matěj Kašpar Jirásek. All rights reserved.
//
// Generated by PaintCode (www.paintcodeapp.com)
//
import UIKit
public class ActivityIndicatorStyleKit : NSObject {
//// Cache
private struct Cache {
static let activityIndicatorBaseColor: UIColor = UIColor(red: 0.333, green: 0.333, blue: 0.333, alpha: 1.000)
static let activityIndicatorHighlightColor: UIColor = UIColor(red: 0.652, green: 0.800, blue: 0.320, alpha: 1.000)
static let activityIndicatorShadow: NSShadow = NSShadow(color: UIColor.lightGrayColor().colorWithAlphaComponent(0.9), offset: CGSize(width: 0.1, height: -0.1), blurRadius: 10)
}
//// Colors
public class var activityIndicatorBaseColor: UIColor { return Cache.activityIndicatorBaseColor }
public class var activityIndicatorHighlightColor: UIColor { return Cache.activityIndicatorHighlightColor }
//// Shadows
public class var activityIndicatorShadow: NSShadow { return Cache.activityIndicatorShadow }
//// Drawing Methods
public class func drawActivityIndicator(step step: CGFloat = 49, width: CGFloat = 9, radius: CGFloat = 18, gap: CGFloat = 3, pieces: CGFloat = 14) {
//// General Declarations
let context = UIGraphicsGetCurrentContext()
//// Variable Declarations
let size: CGFloat = 2 * radius
let length: CGFloat = radius * CGFloat(M_PI) * 2
let centrePoint = CGPoint(x: -radius, y: -radius)
let rotation: CGFloat = 360.0 / pieces * step
let dash: CGFloat = (length - gap * pieces) / pieces
let indicatorAngle: CGFloat = -360 / pieces
//// Oval Drawing
CGContextSaveGState(context)
let ovalPath = UIBezierPath(ovalInRect: CGRect(x: centrePoint.x, y: centrePoint.y, width: size, height: size))
CGContextSaveGState(context)
CGContextSetShadowWithColor(context, ActivityIndicatorStyleKit.activityIndicatorShadow.shadowOffset, ActivityIndicatorStyleKit.activityIndicatorShadow.shadowBlurRadius, (ActivityIndicatorStyleKit.activityIndicatorShadow.shadowColor as! UIColor).CGColor)
UIColor.grayColor().setStroke()
ovalPath.lineWidth = width
CGContextSaveGState(context)
CGContextSetLineDash(context, 0, [dash, gap], 2)
ovalPath.stroke()
CGContextRestoreGState(context)
CGContextRestoreGState(context)
CGContextRestoreGState(context)
//// Indicator Drawing
CGContextSaveGState(context)
CGContextRotateCTM(context, -rotation * CGFloat(M_PI) / 180)
let indicatorRect = CGRect(x: centrePoint.x, y: centrePoint.y, width: size, height: size)
let indicatorPath = UIBezierPath()
indicatorPath.addArcWithCenter(CGPoint(x: indicatorRect.midX, y: indicatorRect.midY), radius: indicatorRect.width / 2, startAngle: 0 * CGFloat(M_PI)/180, endAngle: -indicatorAngle * CGFloat(M_PI)/180, clockwise: true)
ActivityIndicatorStyleKit.activityIndicatorHighlightColor.setStroke()
indicatorPath.lineWidth = width
CGContextSaveGState(context)
CGContextSetLineDash(context, 0, [dash, gap], 2)
indicatorPath.stroke()
CGContextRestoreGState(context)
CGContextRestoreGState(context)
}
//// Generated Images
public class func imageOfActivityIndicator(step step: CGFloat = 49, width: CGFloat = 9, radius: CGFloat = 18, gap: CGFloat = 3, pieces: CGFloat = 14) -> UIImage {
UIGraphicsBeginImageContextWithOptions(CGSize(width: 100, height: 100), false, 0)
let context = UIGraphicsGetCurrentContext()
CGContextTranslateCTM(context, 51, 50)
ActivityIndicatorStyleKit.drawActivityIndicator(step: step, width: width, radius: radius, gap: gap, pieces: pieces)
let imageOfActivityIndicator = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return imageOfActivityIndicator
}
}
extension NSShadow {
convenience init(color: AnyObject!, offset: CGSize, blurRadius: CGFloat) {
self.init()
self.shadowColor = color
self.shadowOffset = offset
self.shadowBlurRadius = blurRadius
}
}
//
// CheckmarkStyleKit.swift
// (null)
//
// Created by Matěj Kašpar Jirásek on 30/03/16.
// Copyright (c) 2016 Matěj Kašpar Jirásek. All rights reserved.
//
// Generated by PaintCode (www.paintcodeapp.com)
//
import UIKit
public class CheckmarkStyleKit : NSObject {
//// Cache
private struct Cache {
static let color: UIColor = UIColor(red: 0.110, green: 0.110, blue: 0.110, alpha: 1.000)
}
//// Colors
public class var color: UIColor { return Cache.color }
//// Drawing Methods
public class func drawCheckmark(time time: CGFloat = 0) {
//// General Declarations
let context = UIGraphicsGetCurrentContext()
//// Variable Declarations
let phase: CGFloat = -time * 1.11
let dash: CGFloat = 57 - time / 100.0 / 2.0 * 57
//// Static line Drawing
let staticLinePath = UIBezierPath()
staticLinePath.moveToPoint(CGPoint(x: 70, y: 30))
staticLinePath.addLineToPoint(CGPoint(x: 30, y: 70))
staticLinePath.lineCapStyle = .Square;
CheckmarkStyleKit.color.setStroke()
staticLinePath.lineWidth = 4
staticLinePath.stroke()
//// Animated line Drawing
let animatedLinePath = UIBezierPath()
animatedLinePath.moveToPoint(CGPoint(x: 30, y: 30))
animatedLinePath.addCurveToPoint(CGPoint(x: 70, y: 70), controlPoint1: CGPoint(x: 30, y: 30), controlPoint2: CGPoint(x: 56.58, y: 56.58))
animatedLinePath.addCurveToPoint(CGPoint(x: 30, y: 70), controlPoint1: CGPoint(x: 83.42, y: 83.42), controlPoint2: CGPoint(x: 46.03, y: 86.03))
animatedLinePath.addCurveToPoint(CGPoint(x: 10, y: 50), controlPoint1: CGPoint(x: 13.97, y: 53.97), controlPoint2: CGPoint(x: 10, y: 50))
animatedLinePath.lineCapStyle = .Square;
CheckmarkStyleKit.color.setStroke()
animatedLinePath.lineWidth = 4
CGContextSaveGState(context)
CGContextSetLineDash(context, phase, [dash, 200], 2)
animatedLinePath.stroke()
CGContextRestoreGState(context)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment