Skip to content
This repository has been archived by the owner on Aug 8, 2020. It is now read-only.

iOS Version #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions iOS/ProgressKit/BaseView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//
// BaseView.swift
// ProgressKit
//
// Created by Kauntey Suryawanshi on 04/10/15.
// Copyright (c) 2015 Kauntey Suryawanshi. All rights reserved.
//

import Foundation
import UIKit
@IBDesignable
open class BaseView : UIView {

override public init(frame frameRect: CGRect) {
super.init(frame: frameRect)
self.configureLayers()
}

required public init?(coder: NSCoder) {
super.init(coder: coder)
//self.configureLayers()
}

/// Configure the Layers
func configureLayers() {
//self.wantsLayer = true
notifyViewRedesigned()
}

@IBInspectable open var background: UIColor = UIColor(red: 88.3 / 256, green: 104.4 / 256, blue: 118.5 / 256, alpha: 1.0) {
didSet {
self.notifyViewRedesigned()
}
}

@IBInspectable open var foreground: UIColor = UIColor(red: 66.3 / 256, green: 173.7 / 256, blue: 106.4 / 256, alpha: 1.0) {
didSet {
self.notifyViewRedesigned()
}
}

@IBInspectable open var cornerRadius: CGFloat = 5.0 {
didSet {
self.notifyViewRedesigned()
}
}

/// Call when any IBInspectable variable is changed
func notifyViewRedesigned() {
self.layer.backgroundColor = background.cgColor
self.layer.cornerRadius = cornerRadius
}

override open func layoutSubviews() {
super.layoutSubviews()
//self.frame will be correct here
configureLayers()
}
}
373 changes: 373 additions & 0 deletions iOS/ProgressKit/ProgressKit.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 46 additions & 0 deletions iOS/ProgressKit/ProgressKit/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//
// AppDelegate.swift
// ProgressKit-iOS
//
// Created by BinaryBoy on 9/27/16.
// Copyright © 2016 Kauntey Suryawanshi. All rights reserved.
//

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?


func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}

func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}

func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}

func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}


}

Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"images" : [
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "29x29",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "29x29",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "40x40",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "40x40",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "60x60",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "60x60",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
27 changes: 27 additions & 0 deletions iOS/ProgressKit/ProgressKit/Base.lproj/LaunchScreen.storyboard
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11134" systemVersion="15F34" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11106"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="EHf-IW-A2E">
<objects>
<viewController id="01J-lp-oVM" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="Llm-lL-Icb"/>
<viewControllerLayoutGuide type="bottom" id="xb3-aO-Qok"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="53" y="375"/>
</scene>
</scenes>
</document>
42 changes: 42 additions & 0 deletions iOS/ProgressKit/ProgressKit/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11201" systemVersion="15G1004" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11161"/>
<capability name="Aspect ratio constraints" minToolsVersion="5.1"/>
<capability name="Constraints with non-1.0 multipliers" minToolsVersion="5.1"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="tne-QT-ifu">
<objects>
<viewController id="BYZ-38-t0r" customClass="ViewController" customModule="ProgressKit" customModuleProvider="target" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="y3c-jy-aDJ"/>
<viewControllerLayoutGuide type="bottom" id="wfy-db-euE"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="19L-bg-uW2" customClass="Spinner" customModule="ProgressKit" customModuleProvider="target">
<color key="backgroundColor" red="0.36078431370000003" green="0.81568627449999997" blue="0.16862745100000001" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="width" secondItem="19L-bg-uW2" secondAttribute="height" multiplier="1:1" id="a6j-dU-YQu"/>
</constraints>
</view>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="19L-bg-uW2" firstAttribute="centerY" secondItem="8bC-Xf-vdC" secondAttribute="centerY" id="2H6-Nx-7da"/>
<constraint firstItem="19L-bg-uW2" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="4Kl-oP-w1w"/>
<constraint firstItem="19L-bg-uW2" firstAttribute="width" secondItem="8bC-Xf-vdC" secondAttribute="width" multiplier="2:3" id="YlW-dF-kAV"/>
</constraints>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
</objects>
</scene>
</scenes>
</document>
104 changes: 104 additions & 0 deletions iOS/ProgressKit/ProgressKit/Determinate/CircularProgressView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
//
// CircularView.swift
// Animo
//
// Created by Kauntey Suryawanshi on 29/06/15.
// Copyright (c) 2015 Kauntey Suryawanshi. All rights reserved.
//

import Foundation
import UIKit

@IBDesignable
open class CircularProgressView: DeterminateAnimation {

var backgroundCircle = CAShapeLayer()
var progressLayer = CAShapeLayer()
var percentLabelLayer = CATextLayer()

@IBInspectable open var strokeWidth: CGFloat = -1 {
didSet {
notifyViewRedesigned()
}
}

@IBInspectable open var showPercent: Bool = true {
didSet {
notifyViewRedesigned()
}
}

override func notifyViewRedesigned() {
super.notifyViewRedesigned()
backgroundCircle.lineWidth = self.strokeWidth / 2
progressLayer.lineWidth = strokeWidth
percentLabelLayer.isHidden = !showPercent

backgroundCircle.strokeColor = foreground.withAlphaComponent(0.5).cgColor
progressLayer.strokeColor = foreground.cgColor
percentLabelLayer.foregroundColor = foreground.cgColor
}

override func updateProgress() {
CATransaction.begin()
if animated {
CATransaction.setAnimationDuration(0.5)
} else {
CATransaction.setDisableActions(true)
}
let timing = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseOut)
CATransaction.setAnimationTimingFunction(timing)
progressLayer.strokeEnd = max(0, min(progress, 1))
percentLabelLayer.string = "\(Int(progress * 100))%"
CATransaction.commit()
}

override func configureLayers() {
super.configureLayers()
let rect = self.bounds
let radius = (rect.width / 2) * 0.75
let strokeScalingFactor = CGFloat(0.05)


// Add background Circle
do {
backgroundCircle.frame = rect
backgroundCircle.lineWidth = strokeWidth == -1 ? (rect.width * strokeScalingFactor / 2) : strokeWidth / 2

backgroundCircle.strokeColor = foreground.withAlphaComponent(0.5).cgColor
backgroundCircle.fillColor = UIColor.clear.cgColor
let backgroundPath = UIBezierPath()
backgroundPath.addArc(withCenter: rect.mid, radius: radius, startAngle: 0, endAngle: 360,clockwise: true)
backgroundCircle.path = backgroundPath.cgPath
self.layer.addSublayer(backgroundCircle)
}

// Progress Layer
do {
progressLayer.strokeEnd = 0 //REMOVe this
progressLayer.fillColor = UIColor.clear.cgColor
progressLayer.lineCap = kCALineCapRound
progressLayer.lineWidth = strokeWidth == -1 ? (rect.width * strokeScalingFactor) : strokeWidth

progressLayer.frame = rect
progressLayer.strokeColor = foreground.cgColor
let arcPath = UIBezierPath()
let startAngle = CGFloat(90)
arcPath.addArc(withCenter: rect.mid, radius: radius, startAngle: startAngle, endAngle: (startAngle - 360), clockwise: true)
progressLayer.path = arcPath.cgPath
self.layer.addSublayer(progressLayer)
}

// Percentage Layer
do {
percentLabelLayer.string = "0%"
percentLabelLayer.foregroundColor = foreground.cgColor
percentLabelLayer.frame = rect
percentLabelLayer.font = "Helvetica Neue Light" as CFTypeRef
percentLabelLayer.alignmentMode = kCAAlignmentCenter
percentLabelLayer.position.y = rect.midY * 0.25
percentLabelLayer.fontSize = rect.width * 0.2
self.layer.addSublayer(percentLabelLayer)
}
}
}
32 changes: 32 additions & 0 deletions iOS/ProgressKit/ProgressKit/Determinate/DeterminateAnimation.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// DeterminateAnimation.swift
// ProgressKit
//
// Created by Kauntey Suryawanshi on 09/07/15.
// Copyright (c) 2015 Kauntey Suryawanshi. All rights reserved.
//

import Foundation
import UIKit

protocol DeterminableAnimation {
func updateProgress()
}

@IBDesignable
open class DeterminateAnimation: BaseView, DeterminableAnimation {

@IBInspectable open var animated: Bool = true

/// Value of progress now. Range 0..1
@IBInspectable open var progress: CGFloat = 0 {
didSet {
updateProgress()
}
}

/// This function will only be called by didSet of progress. Every subclass will have its own implementation
func updateProgress() {
fatalError("Must be overriden in subclass")
}
}
Loading