Monday, April 15, 2024
HomeiOS Developmentios - Animating a Patterned UIView to Mimic Progress Bar

ios – Animating a Patterned UIView to Mimic Progress Bar


I am making an attempt to create a progress bar animation in Swift. I designed a patterned picture to simulate progress however cannot immediately apply this animation to a UIProgressView. As an alternative, I positioned a UIView on high to imitate this habits.

I made a symmetric pic: inexperienced background, with darkish inexperienced horizontal strains.

As I understood, since I can’t connect it on UIProgressBar, I added a UIView to imitate ProgressBar.

The concept is to have one thing like this:
loading bar

This is my present setup:

import UIKit

class SideMenuButtons: UIViewController {
    var progressOverlayView: UIView!
    @IBOutlet weak var energyReloadingIndicator: UIProgressView!
    
    override func viewDidLoad() {
        tremendous.viewDidLoad()
        setupUI()
    }
    
    non-public func setupUI() {
        progressOverlayView = UIView()
        if let patternImage = UIImage(named: "striped-pattern-repeated") {
            progressOverlayView.backgroundColor = UIColor(patternImage: patternImage)
        } else {
            progressOverlayView.backgroundColor = .pink
        }
        energyReloadingIndicator.addSubview(progressOverlayView)
        updateProgressOverlayViewWidth()
    }
    
    non-public func updateProgressOverlayViewWidth() {
        let progress = CGFloat(energyReloadingIndicator.progress)
        let maxWidth = energyReloadingIndicator.body.width
        let overlayWidth = maxWidth * progress
        let overlayHeight = energyReloadingIndicator.body.peak
        progressOverlayView.body = CGRect(x: 0, y: 0, width: overlayWidth, peak: overlayHeight)
    }
}

How can I animate the sample in progressOverlayView to realize a steady transferring impact?



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments