update based on Scott's comment
This commit is contained in:
parent
358842e433
commit
f69fe85d83
@ -8,9 +8,59 @@
|
||||
|
||||
import UIKit
|
||||
|
||||
@objcMembers open class MultiProgress: MFView {
|
||||
@objcMembers open class ProgressBarObject {
|
||||
///from 0.0 to 1.0. input progress should be [0 100]
|
||||
var progress: CGFloat = 0.0
|
||||
///default color is cerulean
|
||||
var color: UIColor = UIColor.mfCerulean()
|
||||
|
||||
init(_ module: [AnyHashable: Any]?) {
|
||||
progress = (module?.optionalCGFloatForKey("progress") ?? 0.0)/100
|
||||
if let colorString = module?.optionalStringForKey("progressColor") {
|
||||
color = UIColor.mfGet(forHex: colorString)
|
||||
}
|
||||
}
|
||||
|
||||
static func getProgressBarObjectList(_ list: [[AnyHashable: Any]]?) -> [ProgressBarObject]? {
|
||||
guard list?.count ?? 0 > 0 else {
|
||||
return nil
|
||||
}
|
||||
var progressList = [ProgressBarObject]()
|
||||
for module in list! {
|
||||
let progressObject = ProgressBarObject(module)
|
||||
progressList.append(progressObject)
|
||||
}
|
||||
return progressList
|
||||
}
|
||||
}
|
||||
|
||||
var progressList: Array<ProgressBarObject>?
|
||||
@objcMembers open class MultiProgress: MFView {
|
||||
///passing value to progressList creates corresponding progress bars
|
||||
var progressList: Array<ProgressBarObject>? {
|
||||
didSet {
|
||||
for subview in subviews {
|
||||
subview.removeFromSuperview()
|
||||
}
|
||||
guard (progressList?.count ?? 0) > 0 else {
|
||||
return
|
||||
}
|
||||
var previous: UIView?
|
||||
for progressObject in progressList! {
|
||||
guard progressObject.progress > 0.0 else {
|
||||
continue
|
||||
}
|
||||
let view = MFView(frame: .zero)
|
||||
view.translatesAutoresizingMaskIntoConstraints = false
|
||||
addSubview(view)
|
||||
view.backgroundColor = progressObject.color
|
||||
view.widthAnchor.constraint(equalTo: widthAnchor, multiplier: progressObject.progress).isActive = true
|
||||
view.leadingAnchor.constraint(equalTo: previous?.trailingAnchor ?? leadingAnchor).isActive = true
|
||||
previous = view
|
||||
NSLayoutConstraint.constraintPinSubview(view, pinTop: true, pinBottom: true, pinLeft: false, pinRight: false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var roundedRect: Bool = false {
|
||||
didSet {
|
||||
if roundedRect {
|
||||
@ -38,58 +88,6 @@ import UIKit
|
||||
super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData)
|
||||
thicknessConstraint?.constant = json?.optionalCGFloatForKey("thickness") ?? defaultHeight
|
||||
roundedRect = json?.optionalBoolForKey("roundedRect") ?? false
|
||||
setupProgressList(json?.optionalArrayForKey("progressList") as? [[AnyHashable: Any]])
|
||||
}
|
||||
|
||||
func setupProgressList(_ list: [[AnyHashable: Any]]?) {
|
||||
for subview in subviews {
|
||||
subview.removeFromSuperview()
|
||||
}
|
||||
let progressObjectList = ProgressBarObject.getProgressBarObjectList(list)
|
||||
progressList = progressObjectList
|
||||
guard (progressList?.count ?? 0) > 0 else {
|
||||
return
|
||||
}
|
||||
var previous: UIView?
|
||||
for progressObject in progressList! {
|
||||
guard progressObject.progress > 0.0 else {
|
||||
continue
|
||||
}
|
||||
let view = MFView(frame: .zero)
|
||||
view.translatesAutoresizingMaskIntoConstraints = false
|
||||
addSubview(view)
|
||||
view.backgroundColor = progressObject.color
|
||||
view.widthAnchor.constraint(equalTo: widthAnchor, multiplier: progressObject.progress).isActive = true
|
||||
view.leadingAnchor.constraint(equalTo: previous?.trailingAnchor ?? leadingAnchor).isActive = true
|
||||
previous = view
|
||||
NSLayoutConstraint.constraintPinSubview(view, pinTop: true, pinBottom: true, pinLeft: false, pinRight: false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@objcMembers open class ProgressBarObject {
|
||||
///from 0.0 to 1.0. input progress should be [0 100]
|
||||
var progress: CGFloat = 0.0
|
||||
///default color is cerulean
|
||||
var color: UIColor = UIColor.mfCerulean()
|
||||
|
||||
init(_ module: [AnyHashable: Any]?) {
|
||||
progress = (module?.optionalCGFloatForKey("progress") ?? 0.0)/100
|
||||
if let colorString = module?.optionalStringForKey("progressColor") {
|
||||
color = UIColor.mfGet(forHex: colorString)
|
||||
}
|
||||
}
|
||||
|
||||
static func getProgressBarObjectList(_ list: [[AnyHashable: Any]]?) -> [ProgressBarObject]? {
|
||||
guard list?.count ?? 0 > 0 else {
|
||||
return nil
|
||||
}
|
||||
var progressList = [ProgressBarObject]()
|
||||
for module in list! {
|
||||
let progressObject = ProgressBarObject(module)
|
||||
progressList.append(progressObject)
|
||||
}
|
||||
return progressList
|
||||
progressList = ProgressBarObject.getProgressBarObjectList(json?.optionalArrayForKey("progressList") as? [[AnyHashable: Any]])
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user