Option to set 'numberOfLines' for label from label's json.

This commit is contained in:
Sumanth Nadigadda 2021-06-05 00:05:54 +05:30
parent c0ae27eab2
commit bba4cbfb66
3 changed files with 22 additions and 0 deletions

View File

@ -316,6 +316,10 @@ public typealias ActionBlock = () -> ()
textColor = color.uiColor textColor = color.uiColor
} }
if let numberofLines = labelModel.numberOfLines {
numberOfLines = numberofLines
}
if let attributes = labelModel.attributes, let labelText = text { if let attributes = labelModel.attributes, let labelText = text {
let attributedString = NSMutableAttributedString(string: labelText, attributes: [NSAttributedString.Key.font: font.updateSize(standardFontSize), NSAttributedString.Key.foregroundColor: textColor as UIColor]) let attributedString = NSMutableAttributedString(string: labelText, attributes: [NSAttributedString.Key.font: font.updateSize(standardFontSize), NSAttributedString.Key.foregroundColor: textColor as UIColor])

View File

@ -25,6 +25,7 @@
public var html: String? public var html: String?
public var hero: Int? public var hero: Int?
public var makeWholeViewClickable: Bool? public var makeWholeViewClickable: Bool?
public var numberOfLines:Int?
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Keys // MARK: - Keys
@ -44,18 +45,30 @@
case html case html
case hero case hero
case makeWholeViewClickable case makeWholeViewClickable
case numberOfLines
} }
enum AttributeTypeKey: String, CodingKey { enum AttributeTypeKey: String, CodingKey {
case type case type
} }
//-----------------------------------------------------
// MARK: - Methods
//-----------------------------------------------------
internal func setDefaults() {
if numberOfLines == nil {
numberOfLines = 1
}
}
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Initializer // MARK: - Initializer
//-------------------------------------------------- //--------------------------------------------------
public init(text: String) { public init(text: String) {
self.text = text self.text = text
setDefaults()
} }
//-------------------------------------------------- //--------------------------------------------------
@ -76,6 +89,7 @@
html = try typeContainer.decodeIfPresent(String.self, forKey: .html) html = try typeContainer.decodeIfPresent(String.self, forKey: .html)
hero = try typeContainer.decodeIfPresent(Int.self, forKey: .hero) hero = try typeContainer.decodeIfPresent(Int.self, forKey: .hero)
makeWholeViewClickable = try typeContainer.decodeIfPresent(Bool.self, forKey: .makeWholeViewClickable) makeWholeViewClickable = try typeContainer.decodeIfPresent(Bool.self, forKey: .makeWholeViewClickable)
numberOfLines = try typeContainer.decodeIfPresent(Int.self, forKey: .numberOfLines)
} }
public func encode(to encoder: Encoder) throws { public func encode(to encoder: Encoder) throws {
@ -93,5 +107,6 @@
try container.encodeIfPresent(html, forKey: .html) try container.encodeIfPresent(html, forKey: .html)
try container.encodeIfPresent(hero, forKey: .hero) try container.encodeIfPresent(hero, forKey: .hero)
try container.encodeIfPresent(makeWholeViewClickable, forKey: .makeWholeViewClickable) try container.encodeIfPresent(makeWholeViewClickable, forKey: .makeWholeViewClickable)
try container.encodeIfPresent(numberOfLines, forKey: .numberOfLines)
} }
} }

View File

@ -73,6 +73,9 @@
headlineBody.set(with: model.headlineBody, delegateObject, additionalData) headlineBody.set(with: model.headlineBody, delegateObject, additionalData)
rightLabel.set(with: model.rightLabel, delegateObject, additionalData) rightLabel.set(with: model.rightLabel, delegateObject, additionalData)
updateAccessibilityLabel() updateAccessibilityLabel()
if let numberOfLines = model.rightLabel.numberOfLines{
rightLabel.numberOfLines = numberOfLines
}
} }
open override class func estimatedHeight(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? { open override class func estimatedHeight(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? {