odedharth / GradientCircularProgress

Customizable progress indicator library in Swift

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Gradient Circular Progress

Customizable progress indicator library in Swift

Requirements

  • Swift 2.0
  • iOS 8.0 or later

Screen Shots

  • All preset styles

Installation

###CocoaPods

  • PodFile [Sample/PodFile]
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!

pod 'GradientCircularProgress', :git => 'https://github.com/keygx/GradientCircularProgress'
  • install
$ pod install

###Carthage

  • Cartfile
github "keygx/GradientCircularProgress"
$ carthage update
  • install

To integrate "GradientCircularProgress.framework" into your Xcode project

Style Settings

Please make your original styles

  • Define custom style structs that implements the StyleProperty Protocol

MyStyle.swift

import GradientCircularProgress

public struct MyStyle : StyleProperty {
    /*** style properties **********************************************************************************/
    
    // Progress Size
    public var progressSize: CGFloat = 200
    
    // Gradient Circular
    public var arcLineWidth: CGFloat = 18.0
    public var startArcColor: UIColor = UIColor.clearColor()
    public var endArcColor: UIColor = UIColor.orangeColor()
    
    // Base Circular
    public var baseLineWidth: CGFloat? = 19.0
    public var baseArcColor: UIColor? = UIColor.darkGrayColor()
    
    // Ratio
    public var ratioLabelFont: UIFont? = UIFont(name: "Verdana-Bold", size: 16.0)
    public var ratioLabelFontColor: UIColor? = UIColor.whiteColor()
    
    // Message
    public var messageLabelFont: UIFont? = UIFont.systemFontOfSize(16.0)
    public var messageLabelFontColor: UIColor? = UIColor.whiteColor()
    
    // Background
    public var backgroundStyle: BackgroundStyles = .Dark
    
    /*** style properties **********************************************************************************/
    
    public init() {}
}

Usage

import GradientCircularProgress

Basic

let progress = GradientCircularProgress()

progress.show(message: "Loading...", MyStyle())
progress.dismiss()

at Rtio

let progress = GradientCircularProgress()

let ratio: CGFloat = CGFloat(totalBytesWritten) / CGFloat(totalBytesExpectedToWrite)        

progress.showAtRatio(style: MyStyle())
progress.updateRatio(ratio)
progress.dismiss()

Update Message

let progress = GradientCircularProgress()

progress.show(message: "Download\n0 / 4", MyStyle())

progress.show(message: "Download\n1 / 4", MyStyle())
progress.show(message: "Download\n2 / 4", MyStyle())
progress.show(message: "Download\n3 / 4", MyStyle())
progress.show(message: "Download\n4 / 4", MyStyle())

let time = dispatch_time(DISPATCH_TIME_NOW, Int64(0.8 * Double(NSEC_PER_SEC)))
dispatch_after(time, dispatch_get_main_queue()) {
    self.progress.updateMessage(message: "Completed!")
    self.progress.dismiss()
}

Download Progress Examples

NSURLSession

let progress = GradientCircularProgress()

~~

progress.showAtRatio(style: BlueDarkStyle())
        
let url = NSURL(string: "http://example.com/download/dummy.mp4")
let config = NSURLSessionConfiguration.defaultSessionConfiguration()
let session = NSURLSession(configuration: config, delegate: self, delegateQueue: NSOperationQueue.mainQueue())
let task = session.downloadTaskWithURL(url!)
task.resume()

~~

// Delegate
func URLSession(session: NSURLSession, downloadTask: NSURLSessionDownloadTask, didWriteData bytesWritten: Int64, totalBytesWritten: Int64, totalBytesExpectedToWrite: Int64) {
    let ratio: CGFloat = CGFloat(totalBytesWritten) / CGFloat(totalBytesExpectedToWrite)
    progress.updateRatio(ratio)
}
// Delegate
func URLSession(session: NSURLSession, downloadTask: NSURLSessionDownloadTask, didFinishDownloadingToURL location: NSURL) {
    progress.dismiss()
}

Alamofire

let progress = GradientCircularProgress()

~~

progress.showAtRatio(style: BlueDarkStyle())

Alamofire.request(.GET, "http://example.com/download/dummy.mp4")
    .response { (request, response, data, error) in
        
        self.progress.dismiss()
}
    .progress { (bytesRead, totalBytesRead, totalBytesExpectedToRead) in
        let ratio: CGFloat = CGFloat(totalBytesRead) / CGFloat(totalBytesExpectedToRead)
        // Call main thread.
        dispatch_async(dispatch_get_main_queue(), {
            self.progress.updateRatio(ratio)
        })
}

API

public func showAtRatio(display display: Bool = true, style: StyleProperty = Style()) -> Void

public func updateRatio(ratio: CGFloat)

public func show(style style: StyleProperty = Style()) -> Void

public func show(message message: String, style: StyleProperty = Style()) -> Void

public func updateMessage(message message: String) -> Void

public func dismiss() -> Void

public func dismiss(completionHandler: () -> Void) -> ()

License

Gradient Circular Progress is released under the MIT license. See LICENSE for details.

Author

Yukihiko Kagiyama (keygx) https://twitter.com/keygx

About

Customizable progress indicator library in Swift

License:MIT License


Languages

Language:Swift 98.0%Language:Objective-C 1.3%Language:Ruby 0.7%