苹果设备安装移动应用程序的进度圈
问题描述:
我正在开发一个类似于我公司的苹果appstore的企业应用程序。在这我有一个要求实现循环下载进度图像相同,当我们从appstore下载或更新任何应用程序时出现的图像。这怎么可以用Swift语言实现。 任何建议将是真正有用的..苹果设备安装移动应用程序的进度圈
答
`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)
答
我正在研究类似的任务,并且今天就设法实现了这一点。我认为最简单的方法是增强当前的用户界面,这样你只需要处理与进度圈相关的部分。
就我而言,我创建了一个名为“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
你可以找到来自cocoascontrol.Use此链接以供参考https://github.com/mrackwitz/MRProgress和https://github.com/PavelKatunin/DownloadButton –
非常感谢你的朋友:) – victorious
: - 很高兴我能帮助ü。 –