### Complete KDCircularProgress Usage Example in Swift Source: https://context7.com/kaandedeoglu/kdcircularprogress/llms.txt A comprehensive Swift example integrating KDCircularProgress within a UIViewController. It covers initialization, appearance configuration, simulating download progress with a Timer, and handling completion and reset actions. ```swift import UIKit import KDCircularProgress class ProgressViewController: UIViewController { var circularProgress: KDCircularProgress! var downloadProgress: Double = 0.0 override func viewDidLoad() { super.viewDidLoad() view.backgroundColor = UIColor(white: 0.22, alpha: 1) // Initialize progress view circularProgress = KDCircularProgress(frame: CGRect(x: 0, y: 0, width: 300, height: 300)) // Configure appearance circularProgress.startAngle = -90 // Start at top circularProgress.progressThickness = 0.2 circularProgress.trackThickness = 0.6 circularProgress.trackColor = UIColor(white: 0.3, alpha: 1) circularProgress.clockwise = true circularProgress.roundedCorners = true circularProgress.glowMode = .forward circularProgress.glowAmount = 0.8 circularProgress.gradientRotateSpeed = 2 // Set gradient colors circularProgress.set(colors: UIColor.cyan, UIColor.white, UIColor.magenta, UIColor.white, UIColor.orange) // Position in view circularProgress.center = view.center view.addSubview(circularProgress) // Simulate download progress simulateDownload() } func simulateDownload() { Timer.scheduledTimer(withTimeInterval: 0.1, repeats: true) { [weak self] timer in guard let self = self else { return } self.downloadProgress += 0.01 self.circularProgress.progress = self.downloadProgress if self.downloadProgress >= 1.0 { timer.invalidate() self.downloadComplete() } } } func downloadComplete() { // Animate completion effect circularProgress.animate(fromAngle: 360, toAngle: 360, duration: 0.3) { completed in print("Download complete!") } } @IBAction func resetButtonTapped(_ sender: UIButton) { circularProgress.animate(toAngle: 0, duration: 0.5) { _ in self.downloadProgress = 0.0 } } @IBAction func animateToFullTapped(_ sender: UIButton) { circularProgress.animate(fromAngle: 0, toAngle: 360, duration: 3.0) { completed in if completed { print("Animation finished") } } } } ``` -------------------------------- ### CocoaPods Integration for KDCircularProgress Source: https://context7.com/kaandedeoglu/kdcircularprogress/llms.txt Instructions for installing and integrating KDCircularProgress into your iOS project using the CocoaPods package manager. Includes Podfile configuration and terminal commands for installation and updates. ```ruby # Podfile platform :ios, '9.0' use_frameworks! target 'MyApp' do pod 'KDCircularProgress', '~> 1.5.4' end ``` ```bash # Terminal commands pod install pod update KDCircularProgress ``` ```swift // In your Swift file import KDCircularProgress class MyViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() let progress = KDCircularProgress( frame: CGRect(x: 0, y: 0, width: 200, height: 200), colors: .systemGreen, .systemYellow, .systemRed ) progress.center = view.center view.addSubview(progress) progress.animate(fromAngle: 0, toAngle: 360, duration: 4, completion: nil) } } ``` -------------------------------- ### Swift Package Manager Integration for KDCircularProgress Source: https://context7.com/kaandedeoglu/kdcircularprogress/llms.txt Steps to add KDCircularProgress to your project using the Swift Package Manager. Includes the necessary configuration in the Package.swift file and example usage in Swift code. ```swift // Package.swift // swift-tools-version:5.0 import PackageDescription let package = Package( name: "MyApp", dependencies: [ .package( url: "https://github.com/kaandedeoglu/KDCircularProgress.git", from: "1.5.4" ) ], targets: [ .target( name: "MyApp", dependencies: ["KDCircularProgress"]) ] ) ``` ```swift // Usage in your code import KDCircularProgress let progress = KDCircularProgress(frame: CGRect(x: 0, y: 0, width: 300, height: 300)) progress.set(colors: .systemBlue, .systemPurple) progress.progressThickness = 0.3 progress.trackThickness = 0.5 progress.startAngle = -90 progress.glowAmount = 0.7 progress.glowMode = .forward // Add to view and animate view.addSubview(progress) progress.animate(fromAngle: 0, toAngle: 360, duration: 5) { completed in print("Animation finished: \(completed)") } ``` -------------------------------- ### Initialize and Configure KDCircularProgress in Swift Source: https://github.com/kaandedeoglu/kdcircularprogress/blob/master/README.md This code snippet demonstrates how to create an instance of KDCircularProgress, configure its appearance including start angle, thickness, colors, glow, and then add it to the view hierarchy. It utilizes IBInspectable properties for easy customization. ```swift progress = KDCircularProgress(frame: CGRect(x: 0, y: 0, width: 300, height: 300)) progress.startAngle = -90 progress.progressThickness = 0.2 progress.trackThickness = 0.6 progress.clockwise = true progress.gradientRotateSpeed = 2 progress.roundedCorners = false progress.glowMode = .forward progress.glowAmount = 0.9 progress.set(colors: UIColor.cyan ,UIColor.white, UIColor.magenta, UIColor.white, UIColor.orange) progress.center = CGPoint(x: view.center.x, y: view.center.y + 25) view.addSubview(progress) ``` -------------------------------- ### Set and Get Progress Values (Swift) Source: https://context7.com/kaandedeoglu/kdcircularprogress/llms.txt Shows how to set the progress of the KDCircularProgress view using either an angle in degrees (0-360) or a normalized value (0.0-1.0). It also demonstrates how to read the current progress values. ```swift let progress = KDCircularProgress(frame: CGRect(x: 0, y: 0, width: 300, height: 300)) progress.set(colors: .cyan, .magenta) view.addSubview(progress) // Set progress using angle (0-360 degrees) progress.angle = 180 // 50% complete (half circle) progress.angle = 90 // 25% complete (quarter circle) progress.angle = 270 // 75% complete // Set progress using normalized value (0.0-1.0) progress.progress = 0.0 // 0% complete progress.progress = 0.5 // 50% complete progress.progress = 1.0 // 100% complete // Read current progress let currentAngle = progress.angle // Returns: 360.0 let currentProgress = progress.progress // Returns: 1.0 ``` -------------------------------- ### Configure Circular Progress Appearance (Swift) Source: https://context7.com/kaandedeoglu/kdcircularprogress/llms.txt Details how to customize the visual properties of the KDCircularProgress view, including start angle, direction, thickness of progress and track, track color, fill color, rounded corners, and gradient rotation speed. ```swift let progress = KDCircularProgress(frame: CGRect(x: 0, y: 0, width: 300, height: 300)) // Set starting angle (-90 starts at top, 0 starts at right) progress.startAngle = -90 // Set progress direction progress.clockwise = true // Configure thickness (0.0 to 1.0) progress.progressThickness = 0.2 // Progress arc thickness progress.trackThickness = 0.6 // Background track thickness // Set track background color progress.trackColor = UIColor.black // Set center fill color progress.progressInsideFillColor = UIColor.darkGray // Enable/disable rounded endpoints progress.roundedCorners = true // Configure gradient rotation (rotations per full progress cycle) progress.gradientRotateSpeed = 2 // Enable color interpolation mode progress.lerpColorMode = false // Add to view hierarchy view.addSubview(progress) ``` -------------------------------- ### Animate CircularProgressView from Angle to Angle in Swift Source: https://github.com/kaandedeoglu/kdcircularprogress/blob/master/README.md Animates the progress bar from a starting angle to an ending angle over a specified duration. An optional completion block can be provided to execute code after the animation finishes. The `relativeDuration` parameter controls whether the duration applies to the specific animation segment or a full rotation. ```swift public func animateFromAngle(fromAngle: Int, toAngle: Int, duration: NSTimeInterval, relativeDuration: Bool = true, completion: ((Bool) -> Void)?) ``` -------------------------------- ### Initialize KDCircularProgress View (Swift) Source: https://context7.com/kaandedeoglu/kdcircularprogress/llms.txt Demonstrates how to initialize the KDCircularProgress view programmatically with a frame or with specified colors. It also shows how to connect it from Interface Builder. ```swift import KDCircularProgress // Initialize with frame let progress = KDCircularProgress(frame: CGRect(x: 0, y: 0, width: 300, height: 300)) // Initialize with frame and colors let progressWithColors = KDCircularProgress( frame: CGRect(x: 0, y: 0, width: 300, height: 300), colors: UIColor.cyan, UIColor.white, UIColor.magenta ) // Initialize from Interface Builder (storyboard/xib) @IBOutlet weak var progress: KDCircularProgress! ``` -------------------------------- ### Advanced Color Configuration for KDCircularProgress Source: https://context7.com/kaandedeoglu/kdcircularprogress/llms.txt Demonstrates different color rendering modes including gradient, lerp mode (color interpolation), and solid colors for KDCircularProgress. This allows for sophisticated visual styling of the progress indicator. ```swift let progress = KDCircularProgress(frame: CGRect(x: 0, y: 0, width: 300, height: 300)) progress.startAngle = -90 // Standard gradient mode (default) progress.lerpColorMode = false progress.set(colors: .red, .yellow, .green) progress.angle = 270 // Result: Colors distributed evenly as gradient stops // Color interpolation mode (smooth color transitions based on angle) progress.lerpColorMode = true progress.set(colors: .blue, .purple, .pink) progress.angle = 180 // Result: Color smoothly interpolates based on current angle // Animated gradient rotation progress.lerpColorMode = false progress.gradientRotateSpeed = 3 // 3 full rotations per progress cycle progress.set(colors: .orange, .red, .purple, .blue) progress.animate(fromAngle: 0, toAngle: 360, duration: 8, completion: nil) // Result: Gradient rotates 3 times while progress completes // Single solid color (no gradient) progress.set(colors: .systemBlue) progress.angle = 200 // Result: Solid blue color throughout progress arc view.addSubview(progress) ``` -------------------------------- ### Interface Builder Integration for KDCircularProgress Source: https://context7.com/kaandedeoglu/kdcircularprogress/llms.txt Configure KDCircularProgress directly in Xcode Interface Builder using IBInspectable properties. This allows for visual design and property tweaking within the storyboard or XIB. Programmatic configuration is needed for dynamic color changes and animations. ```swift // 1. In Interface Builder (Storyboard/XIB): // - Add a UIView to your view controller // - Set the Custom Class to "KDCircularProgress" // - Module: KDCircularProgress // - Set the frame to a square (e.g., 300x300) // 2. Configure properties in Attributes Inspector: // - angle: 180 // - startAngle: -90 // - clockwise: true // - roundedCorners: true // - progressThickness: 0.2 // - trackThickness: 0.6 // - glowAmount: 0.8 // - gradientRotateSpeed: 2.0 // - IBColor1: Cyan (for Interface Builder preview) // - IBColor2: Magenta // - IBColor3: Orange // 3. Create outlet in view controller: class MyViewController: UIViewController { @IBOutlet weak var progressView: KDCircularProgress! override func viewDidLoad() { super.viewDidLoad() // Set colors programmatically (IB colors are for preview only) progressView.set(colors: .cyan, .white, .magenta, .orange) // Animate progressView.animate(fromAngle: 0, toAngle: 360, duration: 5) { _ in print("Progress complete") } } @IBAction func sliderChanged(_ sender: UISlider) { // Manual progress control via slider progressView.angle = Double(sender.value * 360) } } ``` -------------------------------- ### Configure Glow Effects (Swift) Source: https://context7.com/kaandedeoglu/kdcircularprogress/llms.txt Explains how to configure the glow intensity and mode for KDCircularProgress. The glow can be set to increase, decrease, remain constant, or be disabled. It also shows how to animate the progress to observe the glow effect. ```swift let progress = KDCircularProgress(frame: CGRect(x: 0, y: 0, width: 300, height: 300)) progress.set(colors: .cyan, .white, .magenta) // Set glow intensity (0.0 to 1.0, automatically clamped) progress.glowAmount = 0.9 // Configure glow mode progress.glowMode = .forward // Glow increases with progress (0 at start, full at end) // progress.glowMode = .reverse // Glow decreases with progress (full at start, 0 at end) // progress.glowMode = .constant // Constant glow throughout // progress.glowMode = .noGlow // No glow effect view.addSubview(progress) // Animate to see glow effect in action progress.animate(fromAngle: 0, toAngle: 360, duration: 5, completion: nil) ``` -------------------------------- ### Animate Progress Changes in Swift Source: https://context7.com/kaandedeoglu/kdcircularprogress/llms.txt Demonstrates animating the KDCircularProgress from one angle to another with customizable duration and completion callbacks. Supports relative and absolute duration settings. ```swift let progress = KDCircularProgress(frame: CGRect(x: 0, y: 0, width: 300, height: 300)) progress.startAngle = -90 progress.set(colors: .green, .yellow, .red) view.addSubview(progress) // Animate from specific angle to target angle progress.animate( fromAngle: 0, toAngle: 360, duration: 5.0, relativeDuration: true ) { completed in if completed { print("Animation completed successfully") } else { print("Animation was interrupted") } } // Animate from current angle to target angle progress.animate( toAngle: 180, duration: 2.5, relativeDuration: true ) { completed in print("Progress reached 50%") } // Animate with absolute duration (duration represents full 360° rotation) progress.animate( fromAngle: 0, toAngle: 90, duration: 4.0, relativeDuration: false, // 90° will take 1 second (4s / 360° * 90°) completion: nil ) ``` -------------------------------- ### Swift Timer with KDCircularProgress Animation Source: https://context7.com/kaandedeoglu/kdcircularprogress/llms.txt This Swift code demonstrates how to create a responsive circular progress indicator that functions as a timer. It utilizes the KDCircularProgress library to display the elapsed time with smooth animations. The timer updates the progress angle every 0.1 seconds, and triggers a completion animation and message upon reaching the total duration. ```swift import UIKit import KDCircularProgress class TimerViewController: UIViewController { var progress: KDCircularProgress! var timer: Timer? var seconds: Double = 0 let totalSeconds: Double = 60 // 1 minute timer override func viewDidLoad() { super.viewDidLoad() progress = KDCircularProgress(frame: CGRect(x: 0, y: 0, width: 250, height: 250)) progress.startAngle = -90 progress.clockwise = true progress.progressThickness = 0.15 progress.trackThickness = 0.15 progress.trackColor = UIColor.systemGray5 progress.roundedCorners = true progress.glowMode = .constant progress.glowAmount = 0.5 progress.set(colors: .systemBlue, .systemIndigo) progress.center = view.center view.addSubview(progress) } func startTimer() { seconds = 0 progress.angle = 0 timer = Timer.scheduledTimer(withTimeInterval: 0.1, repeats: true) { [weak self] _ in guard let self = self else { return } self.seconds += 0.1 let progressValue = self.seconds / self.totalSeconds self.progress.angle = progressValue * 360 if self.seconds >= self.totalSeconds { self.timerComplete() } } } func timerComplete() { timer?.invalidate() timer = nil // Flash animation on completion UIView.animate(withDuration: 0.2, animations: { self.progress.alpha = 0.3 }) { _ in UIView.animate(withDuration: 0.2) { self.progress.alpha = 1.0 } } print("Timer completed!") } func stopTimer() { timer?.invalidate() timer = nil progress.stopAnimation() } } ``` -------------------------------- ### Initialize CircularProgressView with Gradient Colors in Swift Source: https://github.com/kaandedeoglu/kdcircularprogress/blob/master/README.md Initializes the circular progress view with a frame and an array of gradient colors. Ensure the frame is square for proper display. The colors define the gradient applied to the progress arc. ```swift convenience public init(frame:CGRect, colors: UIColor...) ``` -------------------------------- ### Set Progress Colors (Swift) Source: https://context7.com/kaandedeoglu/kdcircularprogress/llms.txt Explains how to set the gradient colors for the KDCircularProgress view using either variadic parameters or an array of UIColors. A single color can also be set for a non-gradient appearance. ```swift let progress = KDCircularProgress(frame: CGRect(x: 0, y: 0, width: 300, height: 300)) // Method 1: Set colors using variadic parameters progress.set(colors: UIColor.red, UIColor.yellow, UIColor.green) // Method 2: Set colors using array let colorArray: [UIColor] = [.cyan, .white, .magenta, .white, .orange] progress.set(colors: colorArray) // Single color (no gradient) progress.set(colors: UIColor.blue) // Result: Colors are rendered as a gradient across the progress arc ``` -------------------------------- ### Control Active Animations in Swift Source: https://context7.com/kaandedeoglu/kdcircularprogress/llms.txt Shows how to manage ongoing animations of KDCircularProgress, including checking if an animation is active, pausing, resuming, and stopping animations. Stopping resets the progress to 0. ```swift let progress = KDCircularProgress(frame: CGRect(x: 0, y: 0, width: 300, height: 300)) progress.set(colors: .blue, .purple) view.addSubview(progress) // Start an animation progress.animate(fromAngle: 0, toAngle: 360, duration: 10, completion: nil) // Check if animation is running if progress.isAnimating() { print("Animation is currently active") } // Pause the current animation (preserves current state) progress.pauseAnimation() print("Current angle after pause: (progress.angle)") // Resume or start new animation progress.animate(toAngle: 360, duration: 5, completion: nil) // Stop animation completely (resets to angle 0) progress.stopAnimation() print("Angle after stop: (progress.angle)") // Returns: 0.0 ``` -------------------------------- ### Initialize CircularProgressView in Swift Source: https://github.com/kaandedeoglu/kdcircularprogress/blob/master/README.md Initializes the circular progress view with a specified frame. It's recommended to use square frames for consistent results. This initializer does not set any gradient colors. ```swift override public init(frame: CGRect) ``` -------------------------------- ### Pause and Check Animation State in Swift Source: https://github.com/kaandedeoglu/kdcircularprogress/blob/master/README.md Provides methods to control and query the animation state of the circular progress view. `pauseAnimation()` halts any active animation, while `isAnimating()` returns a boolean indicating whether an animation is currently in progress. ```swift public func pauseAnimation() public func isAnimating() -> Bool ``` -------------------------------- ### Animate CircularProgressView to Target Angle in Swift Source: https://github.com/kaandedeoglu/kdcircularprogress/blob/master/README.md Animates the progress bar from its current state to a specified target angle over a given duration. A completion block can be supplied to run code once the animation is complete. This method is useful for smoothly transitioning the progress value. ```swift public func animateToAngle(toAngle: Int, duration: NSTimeInterval, completion: ((Bool) -> Void)?) ``` -------------------------------- ### Set Gradient Colors for CircularProgressView in Swift Source: https://github.com/kaandedeoglu/kdcircularprogress/blob/master/README.md Sets or updates the gradient colors for the circular progress view. This can be done using a variadic array of UIColor or a standard array of UIColor. The method allows dynamic updates to the progress bar's appearance. ```swift public func set(colors: UIColor...) public func set(colors: [UIColor]) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.