constraint convenience
This commit is contained in:
parent
6c92652f01
commit
e7b7012708
@ -19,6 +19,21 @@ open class Arrow: View {
|
||||
return model as? ArrowModel
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Constraints
|
||||
//--------------------------------------------------
|
||||
|
||||
public var heightConstraint: NSLayoutConstraint?
|
||||
public var widthConstraint: NSLayoutConstraint?
|
||||
|
||||
public func pinHeightAndWidth(constant: CGFloat = 12) {
|
||||
|
||||
heightConstraint = heightAnchor.constraint(equalToConstant: constant)
|
||||
widthConstraint = widthAnchor.constraint(equalToConstant: constant)
|
||||
heightConstraint?.isActive = true
|
||||
widthConstraint?.isActive = true
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Lifecycle
|
||||
//--------------------------------------------------
|
||||
|
||||
@ -20,6 +20,9 @@ open class ArrowModel: MoleculeModelProtocol {
|
||||
public var degrees: Float = 0
|
||||
public var lineWidth: CGFloat = 1
|
||||
|
||||
public var height: CGFloat = 12
|
||||
public var width: CGFloat = 12
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Keys
|
||||
//--------------------------------------------------
|
||||
@ -31,6 +34,8 @@ open class ArrowModel: MoleculeModelProtocol {
|
||||
case degrees
|
||||
case size
|
||||
case lineWidth
|
||||
case height
|
||||
case width
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
@ -52,6 +57,14 @@ open class ArrowModel: MoleculeModelProtocol {
|
||||
if let lineWidth = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .lineWidth) {
|
||||
self.lineWidth = lineWidth
|
||||
}
|
||||
|
||||
if let height = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .height) {
|
||||
self.lineWidth = height
|
||||
}
|
||||
|
||||
if let width = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .width) {
|
||||
self.width = width
|
||||
}
|
||||
}
|
||||
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
@ -61,5 +74,7 @@ open class ArrowModel: MoleculeModelProtocol {
|
||||
try container.encode(color, forKey: .color)
|
||||
try container.encode(degrees, forKey: .degrees)
|
||||
try container.encodeIfPresent(backgroundColor, forKey: .lineWidth)
|
||||
try container.encode(width, forKey: .width)
|
||||
try container.encode(height, forKey: .height)
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user