optional check improvements.
This commit is contained in:
parent
d6fdf9958e
commit
71f1f499e0
@ -139,36 +139,35 @@ class Label: UILabel, MVMCoreViewProtocol, MVMCoreUIMoleculeViewProtocol {
|
||||
|
||||
static func setLabel(_ label: UILabel?, withHTML html: String?) {
|
||||
|
||||
let data: Data? = html?.data(using: .utf8)
|
||||
guard let data = html?.data(using: .utf8) else { return }
|
||||
|
||||
if let data = data {
|
||||
do {
|
||||
label?.attributedText = try NSAttributedString(data: data,
|
||||
options: [NSAttributedString.DocumentReadingOptionKey.documentType:NSAttributedString.DocumentType.html, NSAttributedString.DocumentReadingOptionKey.characterEncoding: String.Encoding.utf8.rawValue],
|
||||
documentAttributes: nil)
|
||||
} catch {
|
||||
MVMCoreUILoggingHandler.shared()?.addError(toLog: MVMCoreErrorObject.createErrorObject(for: error, location: "LabelHTMLParse")!)
|
||||
if let coreErrorObject = MVMCoreErrorObject.createErrorObject(for: error, location: "LabelHTMLParse") {
|
||||
MVMCoreUILoggingHandler.shared()?.addError(toLog: coreErrorObject)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static func setUILabel(_ label: UILabel?, withJSON json: [AnyHashable: Any]?, delegate: NSObject?, additionalData: [AnyHashable: Any]?) {
|
||||
|
||||
if let label = label {
|
||||
guard let label = label else { return }
|
||||
|
||||
label.text = json?.optionalStringForKey(KeyText)
|
||||
setLabel(label, withHTML: json?.stringForkey("html"))
|
||||
|
||||
if let textColorHex = json?.optionalStringForKey(KeyTextColor) {
|
||||
if let textColorHex = json?.optionalStringForKey(KeyTextColor), !textColorHex.isEmpty {
|
||||
label.textColor = UIColor.mfGet(forHex: textColorHex)
|
||||
}
|
||||
|
||||
if let backgroundColorHex = json?.optionalStringForKey(KeyBackgroundColor) {
|
||||
if let backgroundColorHex = json?.optionalStringForKey(KeyBackgroundColor), !backgroundColorHex.isEmpty {
|
||||
label.backgroundColor = UIColor.mfGet(forHex: backgroundColorHex)
|
||||
}
|
||||
|
||||
if let accessibilityText = json?.optionalStringForKey("accessibilityText") {
|
||||
label.accessibilityLabel = accessibilityText
|
||||
}
|
||||
label.accessibilityLabel = json?.optionalStringForKey("accessibilityText")
|
||||
|
||||
let fontSize = json?.floatForKey("fontSize") ?? 0.0
|
||||
|
||||
@ -217,7 +216,6 @@ class Label: UILabel, MVMCoreViewProtocol, MVMCoreUIMoleculeViewProtocol {
|
||||
label.attributedText = attributedString
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------
|
||||
// MARK: - Methods
|
||||
@ -310,8 +308,8 @@ class Label: UILabel, MVMCoreViewProtocol, MVMCoreUIMoleculeViewProtocol {
|
||||
|
||||
originalAttributedString = attributedText
|
||||
|
||||
if let actionText = dictionary["actionText"] as? String {
|
||||
self.actionText = actionText
|
||||
}
|
||||
// if let actionText = dictionary["actionText"] as? String {
|
||||
// self.actionText = actionText
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user