### Initialize and Configure GradientProgressBar Source: https://context7.com/fxm90/gradientprogressbar/llms.txt Demonstrates how to initialize a GradientProgressBar, add it to the view hierarchy, set its initial progress, and configure Auto Layout constraints. Use this for basic setup in a UIViewController. ```swift import GradientProgressBar import UIKit final class DownloadViewController: UIViewController { private let gradientProgressBar = GradientProgressBar() private let progressLabel = UILabel() override func viewDidLoad() { super.viewDidLoad() // Configure progress bar gradientProgressBar.translatesAutoresizingMaskIntoConstraints = false view.addSubview(gradientProgressBar) // Set initial progress (value between 0.0 and 1.0) gradientProgressBar.progress = 0.5 // Configure label progressLabel.translatesAutoresizingMaskIntoConstraints = false progressLabel.text = "50%" view.addSubview(progressLabel) // Set up constraints NSLayoutConstraint.activate([ gradientProgressBar.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 24), gradientProgressBar.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -24), gradientProgressBar.centerYAnchor.constraint(equalTo: view.centerYAnchor), gradientProgressBar.heightAnchor.constraint(equalToConstant: 3), progressLabel.topAnchor.constraint(equalTo: gradientProgressBar.bottomAnchor, constant: 8), progressLabel.centerXAnchor.constraint(equalTo: view.centerXAnchor) ]) } // Update progress without animation func updateProgress(to value: Float) { gradientProgressBar.progress = value progressLabel.text = "\(Int(value * 100))%" } // Update progress with animation func animateProgress(to value: Float) { gradientProgressBar.setProgress(value, animated: true) progressLabel.text = "\(Int(value * 100))%" } } ``` -------------------------------- ### UIKit Gradient Progress Bar Setup Source: https://github.com/fxm90/gradientprogressbar/blob/main/README.md Instantiate and add a GradientProgressBar to your UIViewController's view using Auto Layout. Set the progress value after adding it to the view hierarchy. ```swift final class UserRegistrationViewController: UIViewController { private let gradientProgressBar = GradientProgressBar() // ... override func viewDidLoad() { super.viewDidLoad() gradientProgressBar.translatesAutoresizingMaskIntoConstraints = false view.addSubview(gradientProgressBar) NSLayoutConstraint.activate([ gradientProgressBar.leadingAnchor.constraint(equalTo: view.leadingAnchor), gradientProgressBar.trailingAnchor.constraint(equalTo: view.trailingAnchor), gradientProgressBar.topAnchor.constraint(equalTo: view.topAnchor), gradientProgressBar.heightAnchor.constraint(equalToConstant: 3), ]) gradientProgressBar.progress = 0.5 } } ``` -------------------------------- ### Import GradientProgressBar Framework Source: https://github.com/fxm90/gradientprogressbar/blob/main/README.md Import the GradientProgressBar framework into your Swift files after adding it as a dependency. ```swift import GradientProgressBar ``` -------------------------------- ### Add Package via Swift Package Manager Source: https://context7.com/fxm90/gradientprogressbar/llms.txt Configure your Package.swift file to include the GradientProgressBar library. This is the standard method for integrating Swift packages. ```swift // Package.swift dependencies: [ .package( url: "https://github.com/fxm90/GradientProgressBar", from: "4.0.0" ) ] // Target dependency .product( name: "GradientProgressBar", package: "GradientProgressBar" ) ``` -------------------------------- ### Animate GradientProgressBar Progress Source: https://context7.com/fxm90/gradientprogressbar/llms.txt Shows how to animate progress changes using `setProgress(_:animated:)` and configure animation properties like `animationDuration` and `timingFunction`. This is useful for visually indicating progress over time. ```swift import GradientProgressBar import UIKit final class AnimatedProgressViewController: UIViewController { private let gradientProgressBar = GradientProgressBar() override func viewDidLoad() { super.viewDidLoad() gradientProgressBar.translatesAutoresizingMaskIntoConstraints = false view.addSubview(gradientProgressBar) // Configure animation settings gradientProgressBar.animationDuration = 1.0 // 1 second duration gradientProgressBar.timingFunction = .easeInOut // Smooth ease-in-out curve NSLayoutConstraint.activate([ gradientProgressBar.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 24), gradientProgressBar.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -24), gradientProgressBar.centerYAnchor.constraint(equalTo: view.centerYAnchor), gradientProgressBar.heightAnchor.constraint(equalToConstant: 3) ]) // Initial progress gradientProgressBar.progress = 0.0 } func simulateDownload() { // Animated progress update - uses configured animationDuration and timingFunction gradientProgressBar.setProgress(0.25, animated: true) DispatchQueue.main.asyncAfter(deadline: .now() + 1.5) { self.gradientProgressBar.setProgress(0.5, animated: true) } DispatchQueue.main.asyncAfter(deadline: .now() + 3.0) { self.gradientProgressBar.setProgress(0.75, animated: true) } DispatchQueue.main.asyncAfter(deadline: .now() + 4.5) { self.gradientProgressBar.setProgress(1.0, animated: true) } } func instantUpdate() { // Non-animated update - changes immediately gradientProgressBar.progress = 0.5 // Or using setProgress with animated: false gradientProgressBar.setProgress(0.75, animated: false) } } ``` -------------------------------- ### Access Default Configuration Values Source: https://context7.com/fxm90/gradientprogressbar/llms.txt Access and override default configuration values for colors, animation duration, and corner radius for both UIKit and SwiftUI. Requires importing GradientProgressBar. ```swift import GradientProgressBar import SwiftUI import UIKit // Access default UIKit colors let defaultBackgroundColor = UIColor.GradientProgressBar.backgroundColor let defaultGradientColors = UIColor.GradientProgressBar.gradientColors let lightModeBackground = UIColor.GradientProgressBar.BackgroundColor.lightMode let darkModeBackground = UIColor.GradientProgressBar.BackgroundColor.darkMode // Access default SwiftUI colors let swiftUIBackgroundColor = Color.GradientProgressBar.backgroundColor let swiftUIGradientColors = Color.GradientProgressBar.gradientColors // Access default animation duration (0.25 seconds) let defaultAnimationDuration = TimeInterval.GradientProgressBar.progressAnimationDuration // Access default corner radius (1.5 points) let defaultCornerRadius = CGFloat.GradientProgressBar.cornerRadius // Example: Create progress bar with all defaults explicitly struct ExplicitDefaultsView: View { @State private var progress = 0.5 var body: some View { ProgressView(value: progress) .progressViewStyle( .gradientProgressBar( backgroundColor: Color.GradientProgressBar.backgroundColor, gradientColors: Color.GradientProgressBar.gradientColors, cornerRadius: CGFloat.GradientProgressBar.cornerRadius ) ) .frame(height: 3) } } ``` -------------------------------- ### Add Gradient Progress Bar to Package.swift Source: https://github.com/fxm90/gradientprogressbar/blob/main/README.md Add this repository to the dependencies section of your Package.swift file to manage dependencies manually. ```swift dependencies: [ .package( url: "https://github.com/fxm90/GradientProgressBar", from: "4.0.0" ) ] ``` -------------------------------- ### Reference GradientProgressBar Product in Package.swift Source: https://github.com/fxm90/gradientprogressbar/blob/main/README.md Reference the GradientProgressBar product in your target configuration after adding the package dependency. ```swift .product( name: "GradientProgressBar", package: "GradientProgressBar" ) ``` -------------------------------- ### Integrate WKWebView with Gradient Progress Bar Source: https://context7.com/fxm90/gradientprogressbar/llms.txt Attaches a gradient progress bar to a navigation bar to display web page loading progress using Key-Value Observing. Requires importing GradientProgressBar, UIKit, and WebKit. ```swift import GradientProgressBar import UIKit import WebKit final class WebViewController: UIViewController, WKNavigationDelegate { private let webView = WKWebView() private let progressBar = GradientProgressBar() private var progressObserver: NSKeyValueObservation? override func viewDidLoad() { super.viewDidLoad() setupWebView() setupProgressBar() loadInitialPage() } private func setupWebView() { webView.navigationDelegate = self webView.translatesAutoresizingMaskIntoConstraints = false view.addSubview(webView) NSLayoutConstraint.activate([ webView.leadingAnchor.constraint(equalTo: view.leadingAnchor), webView.trailingAnchor.constraint(equalTo: view.trailingAnchor), webView.topAnchor.constraint(equalTo: view.topAnchor), webView.bottomAnchor.constraint(equalTo: view.bottomAnchor) ]) // Observe estimatedProgress using KVO progressObserver = webView.observe(\.estimatedProgress, options: [.new]) { [weak self] webView, _ in Task { @MainActor in self?.progressBar.progress = Float(webView.estimatedProgress) } } } private func setupProgressBar() { guard let navigationBar = navigationController?.navigationBar else { return } progressBar.isHidden = true progressBar.translatesAutoresizingMaskIntoConstraints = false navigationBar.addSubview(progressBar) NSLayoutConstraint.activate([ progressBar.leadingAnchor.constraint(equalTo: navigationBar.leadingAnchor), progressBar.trailingAnchor.constraint(equalTo: navigationBar.trailingAnchor), progressBar.bottomAnchor.constraint(equalTo: navigationBar.bottomAnchor), progressBar.heightAnchor.constraint(equalToConstant: 3) ]) } private func loadInitialPage() { let url = URL(string: "https://apple.com")! let request = URLRequest(url: url) webView.load(request) } // MARK: - WKNavigationDelegate func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) { progressBar.isHidden = false UIView.animate(withDuration: 0.3) { self.progressBar.alpha = 1.0 } } func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) { UIView.animate(withDuration: 0.3) { self.progressBar.alpha = 0.0 } completion: { finished in self.progressBar.isHidden = finished } } } ``` -------------------------------- ### Configure Animation Timing Functions Source: https://context7.com/fxm90/gradientprogressbar/llms.txt Control the animation speed and feel of progress updates using the `timingFunction` property. Supports preset curves like `.linear`, `.easeIn`, `.easeOut`, `.easeInOut`, and custom cubic Bezier curves. ```swift import GradientProgressBar import UIKit final class TimingFunctionDemoViewController: UIViewController { private let gradientProgressBar = GradientProgressBar() override func viewDidLoad() { super.viewDidLoad() gradientProgressBar.translatesAutoresizingMaskIntoConstraints = false gradientProgressBar.animationDuration = 1.5 view.addSubview(gradientProgressBar) NSLayoutConstraint.activate([ gradientProgressBar.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 24), gradientProgressBar.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -24), gradientProgressBar.centerYAnchor.constraint(equalTo: view.centerYAnchor), gradientProgressBar.heightAnchor.constraint(equalToConstant: 3) ]) } // Preset timing functions func demonstrateTimingFunctions() { // Default timing function gradientProgressBar.timingFunction = .default // Linear - constant speed throughout gradientProgressBar.timingFunction = .linear // Ease-in - starts slowly, accelerates toward end gradientProgressBar.timingFunction = .easeIn // Ease-out - starts quickly, decelerates toward end gradientProgressBar.timingFunction = .easeOut // Ease-in-out - starts slowly, speeds up, then slows down gradientProgressBar.timingFunction = .easeInOut // Custom cubic Bezier curve (control points: x1, y1, x2, y2) // This creates a "bounce" effect gradientProgressBar.timingFunction = .custom(x1: 0.68, y1: -0.55, x2: 0.27, y2: 1.55) } func animateWithEaseInOut() { gradientProgressBar.timingFunction = .easeInOut gradientProgressBar.animationDuration = 0.5 gradientProgressBar.setProgress(1.0, animated: true) } } ``` -------------------------------- ### setProgress(_:animated:) Method Source: https://context7.com/fxm90/gradientprogressbar/llms.txt Adjusts the current progress shown by the receiver, optionally animating the change with configurable duration and timing function. ```APIDOC ## UIKit - setProgress(_:animated:) Method Adjusts the current progress shown by the receiver, optionally animating the change with configurable duration and timing function. ### Parameters - **progress** (Float) - The new progress value (between 0.0 and 1.0). - **animated** (Bool) - A boolean value indicating whether the change should be animated. ### Request Example ```swift import GradientProgressBar import UIKit final class AnimatedProgressViewController: UIViewController { private let gradientProgressBar = GradientProgressBar() override func viewDidLoad() { super.viewDidLoad() gradientProgressBar.translatesAutoresizingMaskIntoConstraints = false view.addSubview(gradientProgressBar) // Configure animation settings gradientProgressBar.animationDuration = 1.0 // 1 second duration gradientProgressBar.timingFunction = .easeInOut // Smooth ease-in-out curve NSLayoutConstraint.activate([ gradientProgressBar.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 24), gradientProgressBar.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -24), gradientProgressBar.centerYAnchor.constraint(equalTo: view.centerYAnchor), gradientProgressBar.heightAnchor.constraint(equalToConstant: 3) ]) // Initial progress gradientProgressBar.progress = 0.0 } func simulateDownload() { // Animated progress update - uses configured animationDuration and timingFunction gradientProgressBar.setProgress(0.25, animated: true) DispatchQueue.main.asyncAfter(deadline: .now() + 1.5) { self.gradientProgressBar.setProgress(0.5, animated: true) } DispatchQueue.main.asyncAfter(deadline: .now() + 3.0) { self.gradientProgressBar.setProgress(0.75, animated: true) } DispatchQueue.main.asyncAfter(deadline: .now() + 4.5) { self.gradientProgressBar.setProgress(1.0, animated: true) } } func instantUpdate() { // Non-animated update - changes immediately gradientProgressBar.progress = 0.5 // Or using setProgress with animated: false gradientProgressBar.setProgress(0.75, animated: false) } } ``` ``` -------------------------------- ### Basic SwiftUI ProgressView with Gradient Style Source: https://github.com/fxm90/gradientprogressbar/blob/main/README.md Use the custom `.gradientProgressBar` style for a SwiftUI ProgressView. Ensure the view has a defined frame height. ```swift struct ContentView: View { @State private var progress = 0.5 var body: some View { VStack { ProgressView(value: progress) .progressViewStyle(.gradientProgressBar) .frame(height: 3) Button("Update progress") { progress += 0.1 } } } } ``` -------------------------------- ### SwiftUI Basic Gradient Progress Bar Source: https://context7.com/fxm90/gradientprogressbar/llms.txt Integrate a basic gradient progress bar in SwiftUI using the .gradientProgressBar style. Ensure the progress value is bound to a state variable for updates. ```swift import GradientProgressBar import SwiftUI struct DownloadProgressView: View { @State private var downloadProgress = 0.0 var body: some View { VStack(spacing: 20) { // Basic usage with default gradient colors ProgressView(value: downloadProgress) .progressViewStyle(.gradientProgressBar) .frame(height: 3) // Custom configuration with specific colors and corner radius ProgressView(value: downloadProgress) .progressViewStyle( .gradientProgressBar( backgroundColor: .gray.opacity(0.05), gradientColors: [.indigo, .purple, .pink], cornerRadius: 1.5 ) ) .frame(height: 4) // With animation for smooth progress updates ProgressView(value: downloadProgress) .progressViewStyle(.gradientProgressBar) .animation(.easeInOut(duration: 0.5), value: downloadProgress) .frame(height: 3) Button("Simulate Download") { downloadProgress += 0.1 } .disabled(downloadProgress >= 1.0) } .padding() } } ``` -------------------------------- ### Configurable SwiftUI Gradient ProgressView Source: https://github.com/fxm90/gradientprogressbar/blob/main/README.md Customize the gradient progress bar in SwiftUI by providing background color, gradient colors, and corner radius to the `.gradientProgressBar` style. ```swift ProgressView(value: progress) .progressViewStyle( .gradientProgressBar( backgroundColor: .gray.opacity(0.05), gradientColors: [.indigo, .purple, .pink], cornerRadius: 1.5 ) ) ``` -------------------------------- ### SwiftUI Gradient Progress Bar with Custom Colors Source: https://context7.com/fxm90/gradientprogressbar/llms.txt Create a gradient progress bar in SwiftUI with custom gradient colors and background. The .gradientProgressBar factory method allows detailed customization. ```swift import GradientProgressBar import SwiftUI struct FileUploadView: View { @State private var uploadProgress = 0.3 // Custom pink flamingo gradient colors private let customGradientColors: [Color] = [ Color(red: 0.95, green: 0.32, blue: 0.43), Color(red: 0.95, green: 0.48, blue: 0.59), Color(red: 0.95, green: 0.74, blue: 0.78), Color(red: 0.43, green: 0.87, blue: 0.95), Color(red: 0.76, green: 0.94, blue: 0.96) ] var body: some View { VStack(spacing: 16) { // Default style - returns .gradientProgressBar with default values ProgressView(value: uploadProgress) .progressViewStyle(.gradientProgressBar) .frame(height: 3) // Customized style with all parameters ProgressView(value: uploadProgress) .progressViewStyle( .gradientProgressBar( backgroundColor: Color.gray.opacity(0.1), gradientColors: customGradientColors, cornerRadius: 2.0 ) ) .animation(.easeInOut, value: uploadProgress) .frame(height: 4) HStack { Button("-") { uploadProgress = max(0, uploadProgress - 0.1) } Spacer() Text("\(Int(uploadProgress * 100))%") Spacer() Button("+") { uploadProgress = min(1, uploadProgress + 0.1) } } } .padding() } } ``` -------------------------------- ### Update Progress with Animation Source: https://github.com/fxm90/gradientprogressbar/blob/main/README.md Use this method to update the progress bar's value with a smooth animation. Ensure the `animated` parameter is set to `true` for visual feedback. ```swift gradientProgressBar.setProgress(0.75, animated: true) ``` -------------------------------- ### Configuring UIKit Gradient Progress Bar Source: https://github.com/fxm90/gradientprogressbar/blob/main/README.md Customize the appearance and animation of the UIKit GradientProgressBar by setting its properties like animation duration, gradient colors, and timing function. ```swift let gradientProgressBar = GradientProgressBar() gradientProgressBar.animationDuration = 1 gradientProgressBar.gradientColors = [.systemIndigo, .systemPurple, .systemPink] gradientProgressBar.timingFunction = .easeInOut ``` -------------------------------- ### Update Progress Directly Source: https://github.com/fxm90/gradientprogressbar/blob/main/README.md Set the progress bar's value directly by assigning a new value to the `progress` property. This is useful for instant updates without animation. ```swift gradientProgressBar.progress = 0.75 ``` -------------------------------- ### Set Custom Gradient Colors Source: https://context7.com/fxm90/gradientprogressbar/llms.txt Configure custom gradient colors for the progress bar by assigning an array of UIColor objects to the `gradientColors` property. This replaces the default gradient. ```swift import GradientProgressBar import UIKit final class CustomGradientViewController: UIViewController { private let gradientProgressBar = GradientProgressBar() override func viewDidLoad() { super.viewDidLoad() gradientProgressBar.translatesAutoresizingMaskIntoConstraints = false view.addSubview(gradientProgressBar) // Set custom gradient colors (replaces default iOS-inspired gradient) gradientProgressBar.gradientColors = [ .systemIndigo, .systemPurple, .systemPink ] gradientProgressBar.progress = 0.7 NSLayoutConstraint.activate([ gradientProgressBar.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 24), gradientProgressBar.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -24), gradientProgressBar.centerYAnchor.constraint(equalTo: view.centerYAnchor), gradientProgressBar.heightAnchor.constraint(equalToConstant: 3) ]) } // Change gradient dynamically func setSuccessGradient() { gradientProgressBar.gradientColors = [ UIColor.systemGreen, UIColor.systemTeal ] } func setWarningGradient() { gradientProgressBar.gradientColors = [ UIColor.systemOrange, UIColor.systemYellow ] } func setErrorGradient() { gradientProgressBar.gradientColors = [ UIColor.systemRed, UIColor.systemPink ] } } ``` -------------------------------- ### Animating SwiftUI Gradient ProgressView Updates Source: https://github.com/fxm90/gradientprogressbar/blob/main/README.md Animate changes to the progress value in SwiftUI by applying the `.animation(_:value:)` modifier to the ProgressView. ```swift ProgressView(value: progress) .progressViewStyle(.gradientProgressBar) .animation(.easeInOut, value: progress) ``` -------------------------------- ### GradientProgressBar Class Source: https://context7.com/fxm90/gradientprogressbar/llms.txt The GradientProgressBar is a UIView subclass that renders a horizontal gradient progress bar. It can be used as a replacement for UIProgressView. ```APIDOC ## UIKit - GradientProgressBar Class A `UIView` subclass that renders a horizontal gradient progress bar, serving as a drop-in replacement for `UIProgressView`. ### Properties - **progress** (Float) - The current progress value, typically between 0.0 and 1.0. - **animationDuration** (Double) - The duration for animated progress updates. - **timingFunction** (CAMediaTimingFunction) - The timing function for animated progress updates. ### Methods - **setProgress(_:animated:)** - Adjusts the current progress shown by the receiver, optionally animating the change. ### Example Usage ```swift import GradientProgressBar import UIKit final class DownloadViewController: UIViewController { private let gradientProgressBar = GradientProgressBar() private let progressLabel = UILabel() override func viewDidLoad() { super.viewDidLoad() // Configure progress bar gradientProgressBar.translatesAutoresizingMaskIntoConstraints = false view.addSubview(gradientProgressBar) // Set initial progress (value between 0.0 and 1.0) gradientProgressBar.progress = 0.5 // Configure label progressLabel.translatesAutoresizingMaskIntoConstraints = false progressLabel.text = "50%" view.addSubview(progressLabel) // Set up constraints NSLayoutConstraint.activate([ gradientProgressBar.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 24), gradientProgressBar.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -24), gradientProgressBar.centerYAnchor.constraint(equalTo: view.centerYAnchor), gradientProgressBar.heightAnchor.constraint(equalToConstant: 3), progressLabel.topAnchor.constraint(equalTo: gradientProgressBar.bottomAnchor, constant: 8), progressLabel.centerXAnchor.constraint(equalTo: view.centerXAnchor) ]) } // Update progress without animation func updateProgress(to value: Float) { gradientProgressBar.progress = value progressLabel.text = "\(Int(value * 100))%" } // Update progress with animation func animateProgress(to value: Float) { gradientProgressBar.setProgress(value, animated: true) progressLabel.text = "\(Int(value * 100))%" } } ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.