【问题标题】:Progress circle in Apple devics wihile installing mobile apps安装移动应用程序时 Apple 设备中的进度圈
【发布时间】:2017-04-14 05:48:50
【问题描述】:

我正在为我的公司开发一个类似于苹果应用商店的企业应用程序。在此,我需要实现与我们从应用商店下载或更新任何应用程序时出现的相同的循环下载进度图像。如何使用 Swift 语言来实现。 任何建议都会很有帮助..

欲了解更多信息,请查看

【问题讨论】:

标签: swift mobile-application


【解决方案1】:
`JPCActivityIndicatorButton` is working fine in   `Xcode 8.3` `swift 3.x`   

有用的案例->

   case Names.Spinning:
        activityIndicator.transitionSavedState(Names.ProgressBar)
    case Names.ProgressBar:
                activityIndicator.transitionSavedState(Names.Paused)

代码详情JPActivityIndicatorButton

【讨论】:

    【解决方案2】:

    我正在从事一项类似的任务,今天才设法实施。我认为最简单的方法是增强当前的 UI,以便您只需要处理处理进度圈的部分。

    在我的例子中,我创建了一个名为“UIButtonEnhanced”的新类,它是 UIButton 的子类。

    请注意,在您的界面构建器中,您应该首先将按钮的类更改为“UIButtonEnhanced”,然后创建插座。

    enum DownloadStatus {
        case remote
        case downloading
        case paused
        case resumed
        case success
    }
        // MARK: extension is not ideal, a better solution should be a subclass of UIButton
    class UIButtonEnhanced: UIButton {
        var progress: Float = 0 {
            didSet {
                circleShape.strokeEnd = CGFloat(self.progress)
            }
        }
    
        var circleShape = CAShapeLayer()
        public func drawCircle() {
            let x: CGFloat = 0.0
            let y: CGFloat = 0.0
            let circlePath = UIBezierPath(roundedRect: CGRect(x: x, y: y, width: self.frame.height, height: self.frame.height), cornerRadius: self.frame.height / 2).cgPath
            circleShape.path = circlePath
            circleShape.lineWidth = 3
            circleShape.strokeColor = UIColor.white.cgColor
            circleShape.strokeStart = 0
            circleShape.strokeEnd = 0
            circleShape.fillColor = UIColor.clear.cgColor
            self.layer.addSublayer(circleShape)
        }
    
        // MARK: - Update the download status
        var status: DownloadStatus = .remote {
            didSet{
                var buttonImageName = ""
                switch self.status {
                case .remote:
                    buttonImageName = "DownloadButton"
                case .downloading:
                    buttonImageName = "PauseButton"
                case .success:
                    buttonImageName = "DeleteButton"
                case .paused:
                    buttonImageName = "DownloadButton"
                case .resumed:
                    buttonImageName = "PauseButton"
                }
                self.setImage(UIImage(named: buttonImageName), for: .normal)
            }
        }
        }
    

    在您的 viewController 中,您可以使用以下代码创建圆圈:

        yourButton.drawCircle()
    

    然后当你的下载进度发生变化时,使用这个代码:

        yourButton.progress = 0.5
    

    当您的下载状态发生变化时,请使用此代码:

        yourButton.status = .success
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-10-14
      • 2012-07-16
      • 2016-09-14
      • 2023-03-16
      • 1970-01-01
      • 2012-06-29
      • 2014-07-11
      • 1970-01-01
      相关资源
      最近更新 更多