Percent
This commit is contained in:
parent
2e514a7de5
commit
d4c9753041
@ -27,7 +27,7 @@ import UIKit
|
||||
let view = UIView(frame: .zero)
|
||||
view.translatesAutoresizingMaskIntoConstraints = false
|
||||
addSubview(view)
|
||||
view.backgroundColor = UIColor.mfGet(forHex: progressObject.color)
|
||||
view.backgroundColor = progressObject.color.uiColor
|
||||
view.widthAnchor.constraint(equalTo: widthAnchor, multiplier: progressObject.progress).isActive = true
|
||||
view.leadingAnchor.constraint(equalTo: previous?.trailingAnchor ?? leadingAnchor).isActive = true
|
||||
previous = view
|
||||
|
||||
@ -8,10 +8,14 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
|
||||
@objcMembers public class SingleProgressBarModel: Codable {
|
||||
var progress: CGFloat
|
||||
var color: String
|
||||
@Percent var progress: CGFloat
|
||||
var color: Color
|
||||
|
||||
init(_ progress: CGFloat, color: Color) {
|
||||
self.progress = progress
|
||||
self.color = color
|
||||
}
|
||||
}
|
||||
|
||||
@objcMembers public class MultiProgressBarModel: MoleculeProtocol {
|
||||
|
||||
@ -10,13 +10,11 @@ import Foundation
|
||||
|
||||
@objcMembers public class ProgressBarModel: MoleculeProtocol {
|
||||
public static var identifier: String = "progressbar"
|
||||
|
||||
public var isRounded: Bool?
|
||||
public var thickness: CGFloat?
|
||||
///from 0 to 100
|
||||
@Clamping(range: 0...100) public var percent: CGFloat
|
||||
@Percent public var percent: CGFloat
|
||||
public var progressColor: Color = Color(uiColor: .mfCerulean())
|
||||
public var backgroundColor: Color? = Color(uiColor: .mfLightSilver())
|
||||
public var isRounded: Bool?
|
||||
public var thickness: CGFloat?
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case moleculeName
|
||||
@ -33,8 +31,6 @@ import Foundation
|
||||
|
||||
required public init(from decoder: Decoder) throws {
|
||||
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
|
||||
isRounded = try typeContainer.decodeIfPresent(Bool.self, forKey: .isRounded)
|
||||
thickness = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .thickness)
|
||||
percent = try typeContainer.decode(CGFloat.self, forKey: .percent)
|
||||
if let color = try typeContainer.decodeIfPresent(Color.self, forKey: .progressColor) {
|
||||
progressColor = color
|
||||
@ -42,15 +38,17 @@ import Foundation
|
||||
if let color = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) {
|
||||
backgroundColor = color
|
||||
}
|
||||
isRounded = try typeContainer.decodeIfPresent(Bool.self, forKey: .isRounded)
|
||||
thickness = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .thickness)
|
||||
}
|
||||
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||
try container.encode(moleculeName, forKey: .moleculeName)
|
||||
try container.encodeIfPresent(isRounded, forKey: .isRounded)
|
||||
try container.encodeIfPresent(thickness, forKey: .thickness)
|
||||
try container.encode(percent, forKey: .percent)
|
||||
try container.encode(progressColor, forKey: .progressColor)
|
||||
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
|
||||
try container.encodeIfPresent(isRounded, forKey: .isRounded)
|
||||
try container.encodeIfPresent(thickness, forKey: .thickness)
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user