multi progress changes
This commit is contained in:
parent
7382d9acf5
commit
817e4cb7ba
@ -9,31 +9,38 @@
|
||||
import UIKit
|
||||
|
||||
@objcMembers open class MultiProgress: View {
|
||||
private let stack = Stack<StackModel>()
|
||||
var multiProgressModel: MultiProgressBarModel? {
|
||||
get { return model as? MultiProgressBarModel }
|
||||
}
|
||||
|
||||
|
||||
public required init(model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable : Any]?) {
|
||||
super.init(frame: .zero)
|
||||
set(with: model, delegateObject, additionalData)
|
||||
}
|
||||
|
||||
public required init?(coder: NSCoder) {
|
||||
super.init(coder: coder)
|
||||
}
|
||||
|
||||
public override init(frame: CGRect) {
|
||||
super.init(frame: frame)
|
||||
}
|
||||
|
||||
///passing value to progressList creates corresponding progress bars
|
||||
var progressList: Array<SingleProgressBarModel>? {
|
||||
didSet {
|
||||
for subview in subviews {
|
||||
subview.removeFromSuperview()
|
||||
}
|
||||
guard (progressList?.count ?? 0) > 0 else {
|
||||
return
|
||||
}
|
||||
var previous: UIView?
|
||||
stack.removeAllItemViews()
|
||||
guard (progressList?.count ?? 0) > 0 else { return }
|
||||
var viewModels: [(view: UIView, model: StackItemModel)] = []
|
||||
for progressObject in progressList! {
|
||||
guard progressObject.percent > 0.0 else { continue }
|
||||
let view = UIView(frame: .zero)
|
||||
view.translatesAutoresizingMaskIntoConstraints = false
|
||||
addSubview(view)
|
||||
view.backgroundColor = progressObject.color.uiColor
|
||||
view.widthAnchor.constraint(equalTo: widthAnchor, multiplier: progressObject.percent/100.0).isActive = true
|
||||
view.leadingAnchor.constraint(equalTo: previous?.trailingAnchor ?? leadingAnchor).isActive = true
|
||||
previous = view
|
||||
NSLayoutConstraint.constraintPinSubview(view, pinTop: true, pinBottom: true, pinLeft: false, pinRight: false)
|
||||
let model = StackItemModel(spacing: 0, percent: Int(progressObject.percent), horizontalAlignment: .fill, verticalAlignment: .fill)
|
||||
model.backgroundColor = progressObject.color
|
||||
viewModels.append((view: StackItem(frame: .zero), model: model))
|
||||
}
|
||||
stack.set(with: viewModels)
|
||||
stack.restack()
|
||||
}
|
||||
}
|
||||
|
||||
@ -55,6 +62,8 @@ import UIKit
|
||||
translatesAutoresizingMaskIntoConstraints = false
|
||||
backgroundColor = .mfLightSilver()
|
||||
clipsToBounds = true
|
||||
addSubview(stack)
|
||||
NSLayoutConstraint.constraintPinSubview(toSuperview: stack)
|
||||
if thicknessConstraint == nil {
|
||||
thicknessConstraint = heightAnchor.constraint(equalToConstant: defaultHeight)
|
||||
thicknessConstraint?.isActive = true
|
||||
|
||||
Loading…
Reference in New Issue
Block a user