diff --git a/GradientLoadingBar.podspec b/GradientLoadingBar.podspec index 9172e8d..750465f 100644 --- a/GradientLoadingBar.podspec +++ b/GradientLoadingBar.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'GradientLoadingBar' - s.version = '1.0.0' + s.version = '1.1.0' s.license = { :type => 'MIT', :file => 'LICENSE' } s.summary = 'An animated gradient loading bar.' s.description = 'An animated gradient loading bar. Inspired by http://www.cssscript.com/ios-style-gradient-progress-bar-with-pure-css-css3/' @@ -8,7 +8,7 @@ Pod::Spec.new do |s| s.screenshot = 'http://felix.hamburg/files/github/gradient-loading-bar/screen.gif' s.author = { 'Felix Mau' => 'contact@felix.hamburg' } - s.source = { :git => 'https://github.com/fxm90/GradientLoadingBar.git', :tag => '1.0.0' } + s.source = { :git => 'https://github.com/fxm90/GradientLoadingBar.git', :tag => '1.1.0' } s.source_files = 'GradientLoadingBar', 'GradientLoadingBar/**/*.swift' s.platform = :ios, '9.0' diff --git a/GradientLoadingBar.xcodeproj/project.pbxproj b/GradientLoadingBar.xcodeproj/project.pbxproj index de19778..86cb9d0 100644 --- a/GradientLoadingBar.xcodeproj/project.pbxproj +++ b/GradientLoadingBar.xcodeproj/project.pbxproj @@ -7,6 +7,8 @@ objects = { /* Begin PBXBuildFile section */ + 9725C8891E658B7200C79AEC /* Types.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9725C8881E658B7200C79AEC /* Types.swift */; }; + 977AD2BC1E65871B00E19852 /* GradientLoadingBarDefaultValues.swift in Sources */ = {isa = PBXBuildFile; fileRef = 977AD2BB1E65871B00E19852 /* GradientLoadingBarDefaultValues.swift */; }; 97AE29101E13C5B400C454C6 /* GradientLoadingBar.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 97AE29061E13C5B400C454C6 /* GradientLoadingBar.framework */; }; 97AE29151E13C5B400C454C6 /* GradientLoadingBarTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97AE29141E13C5B400C454C6 /* GradientLoadingBarTests.swift */; }; 97AE29171E13C5B400C454C6 /* GradientLoadingBar.h in Headers */ = {isa = PBXBuildFile; fileRef = 97AE29091E13C5B400C454C6 /* GradientLoadingBar.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -27,6 +29,8 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + 9725C8881E658B7200C79AEC /* Types.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Types.swift; path = Types/Types.swift; sourceTree = ""; }; + 977AD2BB1E65871B00E19852 /* GradientLoadingBarDefaultValues.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = GradientLoadingBarDefaultValues.swift; path = Constants/GradientLoadingBarDefaultValues.swift; sourceTree = ""; }; 97AE29061E13C5B400C454C6 /* GradientLoadingBar.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = GradientLoadingBar.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 97AE29091E13C5B400C454C6 /* GradientLoadingBar.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GradientLoadingBar.h; sourceTree = ""; }; 97AE290A1E13C5B400C454C6 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; @@ -58,6 +62,22 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 973C80121E65722C00346ACE /* Types */ = { + isa = PBXGroup; + children = ( + 9725C8881E658B7200C79AEC /* Types.swift */, + ); + name = Types; + sourceTree = ""; + }; + 977AD2B81E657F8300E19852 /* Constants */ = { + isa = PBXGroup; + children = ( + 977AD2BB1E65871B00E19852 /* GradientLoadingBarDefaultValues.swift */, + ); + name = Constants; + sourceTree = ""; + }; 97AE28FC1E13C5B400C454C6 = { isa = PBXGroup; children = ( @@ -100,8 +120,10 @@ 97AE29211E13C5E500C454C6 /* Helpers */ = { isa = PBXGroup; children = ( + 977AD2B81E657F8300E19852 /* Constants */, 97AE29221E13C5E500C454C6 /* Extensions */, 97AE29241E13C5E500C454C6 /* Structs */, + 973C80121E65722C00346ACE /* Types */, ); path = Helpers; sourceTree = ""; @@ -243,6 +265,8 @@ files = ( 97AE29291E13C5E500C454C6 /* UIColor+Initializers.swift in Sources */, 97AE29281E13C5E500C454C6 /* GradientLoadingBar.swift in Sources */, + 977AD2BC1E65871B00E19852 /* GradientLoadingBarDefaultValues.swift in Sources */, + 9725C8891E658B7200C79AEC /* Types.swift in Sources */, 97AE292B1E13C5E500C454C6 /* GradientView.swift in Sources */, 97AE292A1E13C5E500C454C6 /* Durations.swift in Sources */, ); @@ -450,6 +474,7 @@ 97AE291C1E13C5B400C454C6 /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; 97AE291D1E13C5B400C454C6 /* Build configuration list for PBXNativeTarget "GradientLoadingBarTests" */ = { isa = XCConfigurationList; @@ -458,6 +483,7 @@ 97AE291F1E13C5B400C454C6 /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; /* End XCConfigurationList section */ }; diff --git a/GradientLoadingBar/GradientLoadingBar.swift b/GradientLoadingBar/GradientLoadingBar.swift index a199b5e..411c35a 100644 --- a/GradientLoadingBar/GradientLoadingBar.swift +++ b/GradientLoadingBar/GradientLoadingBar.swift @@ -9,15 +9,11 @@ import Foundation import UIKit -// Default configuration -let defaults = ( - height: 2.5, - durations: Durations(fadeIn: 0.33, fadeOut: 0.66, progress: 3.33) -) - +// Handler for GradientView public class GradientLoadingBar { private let height : Double private let durations : Durations! + private let gradientColors : GradientColors! private lazy var gradientView : GradientView! = self.initGradientView() private var gradientViewAddedToWindow : Bool = false @@ -27,11 +23,13 @@ public class GradientLoadingBar { private static var instance : GradientLoadingBar? public init ( - height: Double = defaults.height, - durations: Durations! = defaults.durations + height: Double = GradientLoadingBarDefaultValues.height, + durations: Durations! = GradientLoadingBarDefaultValues.durations, + gradientColors: GradientColors! = GradientLoadingBarDefaultValues.gradientColors ) { self.height = height self.durations = durations + self.gradientColors = gradientColors self.visibilityCounter = 0 // Used to handle mutliple calls to show/hide at the same time } @@ -50,7 +48,8 @@ public class GradientLoadingBar { let gradientView = GradientView( frame: CGRect(x: frame.origin.x, y: frame.origin.y, width: frame.size.width, height: CGFloat(self.height)), - durations: durations + durations: durations, + gradientColors: gradientColors ) // Add view to main window diff --git a/GradientLoadingBar/Helpers/Constants/GradientLoadingBarDefaultValues.swift b/GradientLoadingBar/Helpers/Constants/GradientLoadingBarDefaultValues.swift new file mode 100644 index 0000000..9547dbf --- /dev/null +++ b/GradientLoadingBar/Helpers/Constants/GradientLoadingBarDefaultValues.swift @@ -0,0 +1,27 @@ +// +// GradientLoadingBarDefaults.swift +// GradientLoadingBar +// +// Created by Felix Mau on 28.02.17. +// Copyright © 2017 Felix Mau. All rights reserved. +// + +import Foundation + +public struct GradientLoadingBarDefaultValues { + static let height = 2.5 + + static let durations = + Durations(fadeIn: 0.33, fadeOut: 0.66, progress: 3.33) + + // iOS color palette + // From: http://www.cssscript.com/ios-style-gradient-progress-bar-with-pure-css-css3/ + public static let gradientColors : GradientColors = [ + UIColor(hexString:"#4cd964").cgColor, + UIColor(hexString:"#5ac8fa").cgColor, + UIColor(hexString:"#007aff").cgColor, + UIColor(hexString:"#34aadc").cgColor, + UIColor(hexString:"#5856d6").cgColor, + UIColor(hexString:"#ff2d55").cgColor + ] +} diff --git a/GradientLoadingBar/Helpers/Types/Types.swift b/GradientLoadingBar/Helpers/Types/Types.swift new file mode 100644 index 0000000..be12746 --- /dev/null +++ b/GradientLoadingBar/Helpers/Types/Types.swift @@ -0,0 +1,11 @@ +// +// GradientColors.swift +// GradientLoadingBar +// +// Created by Felix Mau on 28.02.17. +// Copyright © 2017 Felix Mau. All rights reserved. +// + +import Foundation + +public typealias GradientColors = Array diff --git a/GradientLoadingBar/Views/GradientView.swift b/GradientLoadingBar/Views/GradientView.swift index a3818c7..f663d1f 100644 --- a/GradientLoadingBar/Views/GradientView.swift +++ b/GradientLoadingBar/Views/GradientView.swift @@ -32,19 +32,6 @@ class GradientView : UIView, CAAnimationDelegate { self.gradientLayer.startPoint = CGPoint(x: 0.0, y: 0.0); self.gradientLayer.endPoint = CGPoint(x: 1.0, y: 0.0); - // Colors from http://www.cssscript.com/ios-style-gradient-progress-bar-with-pure-css-css3/ - let gradientColors = [ - UIColor(hexString:"#4cd964").cgColor, - UIColor(hexString:"#5ac8fa").cgColor, - UIColor(hexString:"#007aff").cgColor, - UIColor(hexString:"#34aadc").cgColor, - UIColor(hexString:"#5856d6").cgColor, - UIColor(hexString:"#ff2d55").cgColor - ] - - // Append reversed gradient to simulate infinte animation - self.gradientLayer.colors = gradientColors + gradientColors.reversed() + gradientColors; - // Set default durations to 0 self.durations = Durations() @@ -53,8 +40,13 @@ class GradientView : UIView, CAAnimationDelegate { self.layer.insertSublayer(gradientLayer, at: 0) } - convenience init(frame: CGRect, durations : Durations) { + convenience init(frame: CGRect, durations : Durations, gradientColors : GradientColors) { self.init(frame: frame) + + // Append reversed gradient to simulate infinte animation + self.gradientLayer.colors = + gradientColors + gradientColors.reversed() + gradientColors; + self.durations = durations } diff --git a/readme.md b/readme.md index 06986e5..4e111cf 100644 --- a/readme.md +++ b/readme.md @@ -1,7 +1,7 @@ GradientLoadingBar ==================== -![Swift3.0](https://img.shields.io/badge/Swift-3.0-blue.svg?style=flat) +![Swift3.0](https://img.shields.io/badge/Swift-3.0-green.svg?style=flat) ![Version](https://img.shields.io/cocoapods/v/GradientLoadingBar.svg) An animated gradient loading bar. Inspired by [iOS Style Gradient Progress Bar with Pure CSS/CSS3](http://www.cssscript.com/ios-style-gradient-progress-bar-with-pure-css-css3/). @@ -14,7 +14,7 @@ GradientLoadingBar can be added to your project using [CocoaPods](https://cocoap pod 'GradientLoadingBar', '~> 1.0' ``` ### How to use -First you need to import __"GradientLoadingBar"__. After that you can use __"GradientLoadingBar.sharedInstance()"__ to retrieve an instance to the loading bar. To show it, simply call the __"show()"__ method and after you're done call __"hide()"__. +To get started you need to import __"GradientLoadingBar"__. After that you can use __"GradientLoadingBar.sharedInstance()"__ to retrieve an instance to the loading bar. To show it, simply call the __"show()"__ method and after you're done call __"hide()"__. ``` // Show loading bar GradientLoadingBar.sharedInstance().show() @@ -26,29 +26,39 @@ GradientLoadingBar.sharedInstance().hide() ``` ### Configuration -You can overwrite the default configuration by calling the initializers with the optional params __"height"__ and __"durations"__: +You can overwrite the default configuration by calling the initializers with the optional params __"height"__, __"durations"__ and __"gradientColors"__: ``` let loadingBar = GradientLoadingBar( height: 1.0, - durations: Durations(fadeIn: 1.0, fadeOut: 2.0, progress: 3.00) + durations: Durations(fadeIn: 1.0, fadeOut: 2.0, progress: 3.0) + gradientColors: [ + UIColor(hexString:"#4cd964").cgColor, + UIColor(hexString:"#ff2d55").cgColor + ] ) ``` +For custom colors you have to pass an array with __"CGColor"__ values. For creating those colors you can use all initializers for __"UIColor"__ mentioned here: [UIColor+Initializers.swift](https://gist.github.com/fxm90/1350d27abf92af3be59aaa9eb72c9310) +#### Custom shared instance If you don't want to save the instance on a variable and use the singleton instead, you can use the __"saveInstance()"__ method. Add the following code to your app delegate __"didFinishLaunchingWithOptions"__ method: ``` GradientLoadingBar( height: 1.0, - durations: Durations(fadeIn: 1.0, fadeOut: 2.0, progress: 3.00) + durations: Durations(fadeIn: 1.0, fadeOut: 2.0, progress: 3.00), + gradientColors: [ + UIColor(hexString:"#4cd964").cgColor, + UIColor(hexString:"#ff2d55").cgColor + ] ).saveInstance() ``` After that you can use __"GradientLoadingBar.sharedInstance()"__ as mentioned above. ### Usage with PromiseKit -Check out [my GitHub Gist](https://gist.github.com/fxm90/698554e8335f34e0c6ab95194a4678fb) on how to easily use GradientLoadingBar with [PromiseKit](promisekit.org). +Check out [my GitHub Gist](https://gist.github.com/fxm90/698554e8335f34e0c6ab95194a4678fb) on how to easily use GradientLoadingBar with [PromiseKit](http://promisekit.org/). ### Version -1.0.0 +1.1.0 ### Author Felix Mau (contact(@)felix.hamburg)