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

@ -315,6 +315,10 @@ public typealias ActionBlock = () -> ()
if let color = labelModel.textColor {
textColor = color.uiColor
}
if let numberofLines = labelModel.numberOfLines {
numberOfLines = numberofLines
}
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])

View File

@ -25,6 +25,7 @@
public var html: String?
public var hero: Int?
public var makeWholeViewClickable: Bool?
public var numberOfLines:Int?
//--------------------------------------------------
// MARK: - Keys
@ -44,18 +45,30 @@
case html
case hero
case makeWholeViewClickable
case numberOfLines
}
enum AttributeTypeKey: String, CodingKey {
case type
}
//-----------------------------------------------------
// MARK: - Methods
//-----------------------------------------------------
internal func setDefaults() {
if numberOfLines == nil {
numberOfLines = 1
}
}
//--------------------------------------------------
// MARK: - Initializer
//--------------------------------------------------
public init(text: String) {
self.text = text
setDefaults()
}
//--------------------------------------------------
@ -76,6 +89,7 @@
html = try typeContainer.decodeIfPresent(String.self, forKey: .html)
hero = try typeContainer.decodeIfPresent(Int.self, forKey: .hero)
makeWholeViewClickable = try typeContainer.decodeIfPresent(Bool.self, forKey: .makeWholeViewClickable)
numberOfLines = try typeContainer.decodeIfPresent(Int.self, forKey: .numberOfLines)
}
public func encode(to encoder: Encoder) throws {
@ -93,5 +107,6 @@
try container.encodeIfPresent(html, forKey: .html)
try container.encodeIfPresent(hero, forKey: .hero)
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)
rightLabel.set(with: model.rightLabel, delegateObject, additionalData)
updateAccessibilityLabel()
if let numberOfLines = model.rightLabel.numberOfLines{
rightLabel.numberOfLines = numberOfLines
}
}
open override class func estimatedHeight(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? {