Coder Social home page Coder Social logo

trendingtechnology / dsgradientprogressview Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dholstudio/dsgradientprogressview

0.0 2.0 0.0 350 KB

A simple animated progress bar in Swift

License: Apache License 2.0

Ruby 9.98% Objective-C 8.17% Swift 81.85%

dsgradientprogressview's Introduction

DSGradientProgressView

Swift Version License CocoaPods Compatible Platform

Introduction

DSGradientProgressView is a simple and customizable animated progress bar written in Swift.

Inspired by GradientProgressView.

Demo

Demo gif

The gif looks flickery, but the actual animation on device will not be.

Usage

Simply drop a UIView into your View Controller in the Storyboard. Select your view and, in the Identity Inspector, change the class to DSGradientProgressView.

Don't forget to change the module to DSGradientProgressView too.

Demo set class

Size the view according to your needs. (A 3px height looks great in most cases).

Import DSGradientProgressView in your view controller source file.

import DSGradientProgressView

Create an IBOutlet of the view in your view controller source file.

@IBOutlet weak var progressView: DSGradientProgressView!

Customize

You can change the base color of the progress bar. There are two ways to do this:

  • By setting the barColor property of the view object in your source file.
progressView.barColor = UIColor.green
  • Changing the Bar Color property in Storyboard itself.

Demo color picker

Animate

DSGradientProgressView is designed to keep track of the number of requests waiting for completion. Hence the api's are named after semaphore method names. You call the wait() method of the DSGradientProgressView to start animating and signal() method to stop. It hides and un-hides itself accordingly.

progressView.wait()
  // waiting for some resource
progressView.signal()

So, if your View Controller is waiting for more than one network request (or any other resource) and you want the Progress Bar to animate until all the requests are over, you can do that by simply calling wait() that number of times. Later, call signal() the same number of times.

progressView.wait()
  // waiting for some resource asynchronously
ResourceOne.sharedInstance.fetchData { (data, error) in
         self.progressView.signal()
}

progressView.wait()
  // waiting for another resource asynchronously
ResourceTwo.sharedInstance.fetchData { (data, error) in
         self.progressView.signal()
}

Installation

CocoaPods (Recommended)

CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

$ gem install cocoapods

CocoaPods 1.1.0+ is required to build DSGradientProgressView 1.0.0+.

To integrate DSGradientProgressView into your Xcode project using CocoaPods, specify it in your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '10.0'
use_frameworks!

target '<Your Target Name>' do
    pod 'DSGradientProgressView'
end

Then, run the following command:

$ pod install

Manually

Copy the DSGradientProgressView.swift to your Xcode project. That should do it.

Requirements

  • iOS 8.0+
  • Xcode 10.0+
  • Swift 4.2+

Contacts

dsgradientprogressview's People

Contributors

iabtyagi avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.