Skip to content

Instantly share code, notes, and snippets.

@FredLoh
Last active November 15, 2015 20:28
Show Gist options
  • Save FredLoh/38354cfe65408f8bc23e to your computer and use it in GitHub Desktop.
Save FredLoh/38354cfe65408f8bc23e to your computer and use it in GitHub Desktop.
class ReadingsIndividualArticle: UIViewController, UIActionSheetDelegate, AVAudioPlayerDelegate {
let progressView = ProgressView()
override func viewDidLoad() {
middleView.backgroundColor = UIColor.whiteColor()
self.view.addSubview(middleView)
middleView.addSubview(progressView)
progressView.backgroundColor = UIColor.whiteColor()
middleView.snp_makeConstraints { (make) -> Void in
make.left.top.right.bottom.equalTo(self.view)
}
progressView.snp_makeConstraints { (make) -> Void in
make.left.right.bottom.equalTo(middleView)
make.centerX.equalTo(middleView)
make.height.equalTo(34)
}
}
}
//
// ProgressStyleKit.swift
// ProgressBar
//
// Created by Fred on 14/Nov/15.
// Copyright (c) 2015 Outloud. All rights reserved.
//
// Generated by PaintCode (www.paintcodeapp.com)
//
import UIKit
public class ProgressStyleKit : NSObject {
//// Drawing Methods
public class func drawProgressBarCanvas(width: CGFloat) {
//// General Declarations
let context = UIGraphicsGetCurrentContext()
//// Color Declarations
let gradientColor = UIColor(red: 0.322, green: 0.322, blue: 0.322, alpha: 1.000)
let gradientColor2 = UIColor(red: 0.416, green: 0.416, blue: 0.416, alpha: 1.000)
let shadowColor = UIColor(red: 0.200, green: 0.200, blue: 0.200, alpha: 1.000)
let innerShadowColor = UIColor(red: 0.671, green: 0.671, blue: 0.671, alpha: 1.000)
let gradientColor3 = UIColor(red: 0.188, green: 0.188, blue: 0.188, alpha: 1.000)
let gradientColor4 = UIColor(red: 0.247, green: 0.247, blue: 0.247, alpha: 1.000)
let progressColor = UIColor(red: 0.000, green: 0.886, blue: 0.000, alpha: 1.000)
//// Gradient Declarations
let outerRectGradient = CGGradientCreateWithColors(CGColorSpaceCreateDeviceRGB(), [gradientColor.CGColor, gradientColor2.CGColor], [0, 1])!
let trackGradient = CGGradientCreateWithColors(CGColorSpaceCreateDeviceRGB(), [gradientColor3.CGColor, gradientColor4.CGColor], [0, 1])!
//// Shadow Declarations
let darkShadow = NSShadow()
darkShadow.shadowColor = shadowColor
darkShadow.shadowOffset = CGSizeMake(0.1, 1.1)
darkShadow.shadowBlurRadius = 1.5
let innerShadow = NSShadow()
innerShadow.shadowColor = innerShadowColor
innerShadow.shadowOffset = CGSizeMake(0.1, 1.1)
innerShadow.shadowBlurRadius = 0
//// Frames
let progressIndicatorFrame = CGRectMake(0, 0, width, 34)
//// Subframes
let progressActiveGroup: CGRect = CGRectMake(progressIndicatorFrame.minX + 12, progressIndicatorFrame.minY + 11, progressIndicatorFrame.width - 28, 10)
let activeProgressFrame = CGRectMake(progressActiveGroup.minX + floor(progressActiveGroup.width * 0.00000 + 0.5), progressActiveGroup.minY, floor(progressActiveGroup.width * 1.00000 + 0.5) - floor(progressActiveGroup.width * 0.00000 + 0.5), 10)
//// ProgressBarGroup
//// Border Drawing
let borderRect = CGRectMake(progressIndicatorFrame.minX, progressIndicatorFrame.minY, progressIndicatorFrame.width, 34)
let borderPath = UIBezierPath(roundedRect: borderRect, cornerRadius: 4)
CGContextSaveGState(context)
CGContextSetShadowWithColor(context, darkShadow.shadowOffset, darkShadow.shadowBlurRadius, (darkShadow.shadowColor as! UIColor).CGColor)
CGContextBeginTransparencyLayer(context, nil)
borderPath.addClip()
CGContextDrawLinearGradient(context, outerRectGradient,
CGPointMake(borderRect.midX, borderRect.minY),
CGPointMake(borderRect.midX, borderRect.maxY),
CGGradientDrawingOptions())
CGContextEndTransparencyLayer(context)
////// Border Inner Shadow
CGContextSaveGState(context)
CGContextClipToRect(context, borderPath.bounds)
CGContextSetShadow(context, CGSizeMake(0, 0), 0)
CGContextSetAlpha(context, CGColorGetAlpha((innerShadow.shadowColor as! UIColor).CGColor))
CGContextBeginTransparencyLayer(context, nil)
let borderOpaqueShadow = (innerShadow.shadowColor as! UIColor).colorWithAlphaComponent(1)
CGContextSetShadowWithColor(context, innerShadow.shadowOffset, innerShadow.shadowBlurRadius, borderOpaqueShadow.CGColor)
CGContextSetBlendMode(context, .SourceOut)
CGContextBeginTransparencyLayer(context, nil)
borderOpaqueShadow.setFill()
borderPath.fill()
CGContextEndTransparencyLayer(context)
CGContextEndTransparencyLayer(context)
CGContextRestoreGState(context)
CGContextRestoreGState(context)
//// ProgressTrack Drawing
let progressTrackRect = CGRectMake(progressIndicatorFrame.minX + 10, progressIndicatorFrame.minY + 9, progressIndicatorFrame.width - 24, 14)
let progressTrackPath = UIBezierPath(roundedRect: progressTrackRect, cornerRadius: 7)
CGContextSaveGState(context)
CGContextSetShadowWithColor(context, innerShadow.shadowOffset, innerShadow.shadowBlurRadius, (innerShadow.shadowColor as! UIColor).CGColor)
CGContextBeginTransparencyLayer(context, nil)
progressTrackPath.addClip()
CGContextDrawLinearGradient(context, trackGradient,
CGPointMake(progressTrackRect.midX, progressTrackRect.minY),
CGPointMake(progressTrackRect.midX, progressTrackRect.maxY),
CGGradientDrawingOptions())
CGContextEndTransparencyLayer(context)
////// ProgressTrack Inner Shadow
CGContextSaveGState(context)
CGContextClipToRect(context, progressTrackPath.bounds)
CGContextSetShadow(context, CGSizeMake(0, 0), 0)
CGContextSetAlpha(context, CGColorGetAlpha((darkShadow.shadowColor as! UIColor).CGColor))
CGContextBeginTransparencyLayer(context, nil)
let progressTrackOpaqueShadow = (darkShadow.shadowColor as! UIColor).colorWithAlphaComponent(1)
CGContextSetShadowWithColor(context, darkShadow.shadowOffset, darkShadow.shadowBlurRadius, progressTrackOpaqueShadow.CGColor)
CGContextSetBlendMode(context, .SourceOut)
CGContextBeginTransparencyLayer(context, nil)
progressTrackOpaqueShadow.setFill()
progressTrackPath.fill()
CGContextEndTransparencyLayer(context)
CGContextEndTransparencyLayer(context)
CGContextRestoreGState(context)
CGContextRestoreGState(context)
//// ProgressActiveGroup
//// ProgressBar Drawing
let progressBarPath = UIBezierPath(roundedRect: CGRectMake(activeProgressFrame.minX, activeProgressFrame.minY + activeProgressFrame.height - 10, floor((activeProgressFrame.width) * 1.00000 + 0.5), 10), cornerRadius: 5)
CGContextSaveGState(context)
CGContextSetShadowWithColor(context, innerShadow.shadowOffset, innerShadow.shadowBlurRadius, (innerShadow.shadowColor as! UIColor).CGColor)
progressColor.setFill()
progressBarPath.fill()
////// ProgressBar Inner Shadow
CGContextSaveGState(context)
CGContextClipToRect(context, progressBarPath.bounds)
CGContextSetShadow(context, CGSizeMake(0, 0), 0)
CGContextSetAlpha(context, CGColorGetAlpha((darkShadow.shadowColor as! UIColor).CGColor))
CGContextBeginTransparencyLayer(context, nil)
let progressBarOpaqueShadow = (darkShadow.shadowColor as! UIColor).colorWithAlphaComponent(1)
CGContextSetShadowWithColor(context, darkShadow.shadowOffset, darkShadow.shadowBlurRadius, progressBarOpaqueShadow.CGColor)
CGContextSetBlendMode(context, .SourceOut)
CGContextBeginTransparencyLayer(context, nil)
progressBarOpaqueShadow.setFill()
progressBarPath.fill()
CGContextEndTransparencyLayer(context)
CGContextEndTransparencyLayer(context)
CGContextRestoreGState(context)
CGContextRestoreGState(context)
}
}
import Foundation
import UIKit
class ProgressView: UIView {
let rect = CGRectMake(2, 1, 318, 34)
override func drawRect(rect: CGRect) {
ProgressStyleKit.drawProgressBarCanvas(self.frame.width)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment