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?) {
|
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 {
|
do {
|
||||||
label?.attributedText = try NSAttributedString(data: data,
|
label?.attributedText = try NSAttributedString(data: data,
|
||||||
options: [NSAttributedString.DocumentReadingOptionKey.documentType:NSAttributedString.DocumentType.html, NSAttributedString.DocumentReadingOptionKey.characterEncoding: String.Encoding.utf8.rawValue],
|
options: [NSAttributedString.DocumentReadingOptionKey.documentType:NSAttributedString.DocumentType.html, NSAttributedString.DocumentReadingOptionKey.characterEncoding: String.Encoding.utf8.rawValue],
|
||||||
documentAttributes: nil)
|
documentAttributes: nil)
|
||||||
} catch {
|
} 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]?) {
|
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)
|
label.text = json?.optionalStringForKey(KeyText)
|
||||||
setLabel(label, withHTML: json?.stringForkey("html"))
|
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)
|
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)
|
label.backgroundColor = UIColor.mfGet(forHex: backgroundColorHex)
|
||||||
}
|
}
|
||||||
|
|
||||||
if let accessibilityText = json?.optionalStringForKey("accessibilityText") {
|
label.accessibilityLabel = json?.optionalStringForKey("accessibilityText")
|
||||||
label.accessibilityLabel = accessibilityText
|
|
||||||
}
|
|
||||||
|
|
||||||
let fontSize = json?.floatForKey("fontSize") ?? 0.0
|
let fontSize = json?.floatForKey("fontSize") ?? 0.0
|
||||||
|
|
||||||
@ -217,7 +216,6 @@ class Label: UILabel, MVMCoreViewProtocol, MVMCoreUIMoleculeViewProtocol {
|
|||||||
label.attributedText = attributedString
|
label.attributedText = attributedString
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------
|
//------------------------------------------------------
|
||||||
// MARK: - Methods
|
// MARK: - Methods
|
||||||
@ -310,8 +308,8 @@ class Label: UILabel, MVMCoreViewProtocol, MVMCoreUIMoleculeViewProtocol {
|
|||||||
|
|
||||||
originalAttributedString = attributedText
|
originalAttributedString = attributedText
|
||||||
|
|
||||||
if let actionText = dictionary["actionText"] as? String {
|
// if let actionText = dictionary["actionText"] as? String {
|
||||||
self.actionText = actionText
|
// self.actionText = actionText
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user