可自定义的渐变进度条(UIProgressView)

渐变进度条

雨燕5.0 CI 状态 代码覆盖率 版本 许可证 平台

可自定义的渐变进度条 (UIProgressView)。灵感来自 Codepen 的 iOS 7 进度条

例

To run the example project, clone the repo, and open the workspace from the Example directory.

Requirements

  • Swift 5.0
  • Xcode 11
  • iOS 9.0+

Integration

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. For usage and installation instructions, visit their website. To integrate GradientProgressBar into your Xcode project using CocoaPods, specify it in your :Podfile

pod 'GradientProgressBar', '~> 2.0'
Ruby
Carthage

Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks. To integrate GradientProgressBar into your Xcode project using Carthage, specify it in your :Cartfile

github "fxm90/GradientProgressBar" ~> 2.0
Ogdl

Run carthage update to build the framework and drag the built , as well as the dependency , into your Xcode project.GradientProgressBar.frameworkLightweightObservable.framework

Swift Package Manager

The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the compiler. It is in early development, but Gradient Progress Bar does support its use on supported platforms.swift

Once you have your Swift package set up, adding Gradient Progress Bar as a dependency is as easy as adding it to the value of your .dependenciesPackage.swift

dependencies: [
    .package(url: "https://github.com/fxm90/GradientProgressBar", from: "2.0.3")
]
Swift

How to use

Simply drop a into your View Controller in the Storyboard. Select your view and in the change the class to .UIViewIdentity InspectorGradientProgressBar

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

Interface Builder

Setup the constraints for the according to your needs.UIView

Import in your view controller source file.GradientProgressBar

import GradientProgressBar
Swift

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

@IBOutlet weak var gradientProgressView: GradientProgressBar!
Swift

After that you can set the progress programmatically as you would do on a normal UIProgressView.

gradientProgressView.setProgress(0.75, animated: true)
Swift
gradientProgressView.progress = 0.75
Swift

Configuration

– Property animationDuration

Adjusts the animation duration for calls to :setProgress(_:animated:)

progressView.animationDuration = 2.0
progressView.setProgress(progress, animated: true)
Swift

– Property gradientColors

Adjusts the colors, used for the gradient inside the progress-view.

progressView.gradientColors: [UIColor] = [
    .red,
    .white,
    .blue
]
Swift

– Property timingFunction

Adjusts the timing function for calls to , with animated set to .setProgress(_:animated:)true

progressView.timingFunction = CAMediaTimingFunction(name: .easeInEaseOut)
Swift

Troubleshooting

Interface Builder Support

Unfortunatly the Interface Builder support is currently broken for Cocoapods frameworks. If you need Interface Builder support, add the following code to your Podfile and run again. Afterwards you should be able to use the inside the Interface Builder :)pod installGradientProgressBar

  post_install do |installer|
    installer.pods_project.build_configurations.each do |config|
      next unless config.name == 'Debug'

      config.build_settings['LD_RUNPATH_SEARCH_PATHS'] = [
        '$(FRAMEWORK_SEARCH_PATHS)'
      ]
    end
  end

Source: Cocoapods – Issue 7606

Show progress of WKWebView

Based on my gist, the example application also contains the sample code, for attaching the progress view to a . Using "Key-Value Observing" we change the progress of the bar accordingly to the property of the .UINavigationBarestimatedProgressWKWebView

Please have a look at the example application for further details :)

Author

Felix Mau (me(@)felix.hamburg)

License

GradientProgressBar is available under the MIT license. See the LICENSE file for more info.

GitHub

https://github.com/fxm90/GradientProgressBar