Unnecessary import. Simplified code. Fixed font optional.
This commit is contained in:
parent
83dda81d55
commit
3d2059754c
@ -168,20 +168,20 @@ import MVMCore
|
|||||||
|
|
||||||
label.accessibilityLabel = json?.optionalStringForKey("accessibilityText")
|
label.accessibilityLabel = json?.optionalStringForKey("accessibilityText")
|
||||||
|
|
||||||
let fontSize = json?.floatForKey("fontSize") ?? 0.0
|
let fontSize = json?["fontSize"] as? CGFloat
|
||||||
|
|
||||||
if let fontName = json?.optionalStringForKey("fontName") {
|
if let fontName = json?.optionalStringForKey("fontName") {
|
||||||
label.font = MFFonts.mfFont(withName: fontName, size: fontSize == 0.0 ? label.font.pointSize : CGFloat(fontSize))
|
label.font = MFFonts.mfFont(withName: fontName, size: fontSize ?? label.font.pointSize)
|
||||||
} else {
|
} else if let fontSize = fontSize {
|
||||||
label.font = label.font.withSize(CGFloat(fontSize))
|
label.font = label.font.withSize(fontSize)
|
||||||
}
|
}
|
||||||
|
|
||||||
if let attributes = json?.arrayForKey("attributes"), let labelText = label.text {
|
if let attributes = json?.arrayForKey("attributes"), let labelText = label.text {
|
||||||
let attributedString = NSMutableAttributedString(string: labelText, attributes: [NSAttributedString.Key.font: label.font as Any,
|
let attributedString = NSMutableAttributedString(string: labelText, attributes: [NSAttributedString.Key.font: label.font as Any,
|
||||||
NSAttributedString.Key.foregroundColor: label.textColor as Any])
|
NSAttributedString.Key.foregroundColor: label.textColor as Any])
|
||||||
for case let attribute as [String: Any] in attributes {
|
for case let attribute as [String: Any] in attributes {
|
||||||
let range = NSRange(location: Int(attribute.floatForKey("location")),
|
|
||||||
length: Int(attribute.floatForKey("length")))
|
let range = NSRange(location: json?["location"] as? Int ?? 0, length: json?["length"] as? Int ?? 0)
|
||||||
|
|
||||||
guard let attributeType = attribute.optionalStringForKey(KeyType) else { continue }
|
guard let attributeType = attribute.optionalStringForKey(KeyType) else { continue }
|
||||||
|
|
||||||
@ -197,17 +197,18 @@ import MVMCore
|
|||||||
attributedString.addAttribute(.foregroundColor, value: UIColor.mfGet(forHex: colorHex), range: range)
|
attributedString.addAttribute(.foregroundColor, value: UIColor.mfGet(forHex: colorHex), range: range)
|
||||||
}
|
}
|
||||||
case "font":
|
case "font":
|
||||||
let fontSize = attribute.floatForKey("size")
|
let fontSize = json?["size"] as? CGFloat
|
||||||
let font: UIFont?
|
var font: UIFont?
|
||||||
|
|
||||||
if let fontName = attribute.optionalStringForKey("name"), !fontName.isEmpty {
|
if let fontName = attribute.optionalStringForKey("name") {
|
||||||
font = MFFonts.mfFont(withName: fontName, size: fontSize != 0.0 ? CGFloat(fontSize) : CGFloat(label.font.pointSize))
|
font = MFFonts.mfFont(withName: fontName, size: fontSize ?? label.font.pointSize)
|
||||||
} else {
|
} else if let fontSize = fontSize {
|
||||||
font = label.font.withSize(CGFloat(fontSize))
|
font = label.font.withSize(fontSize)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if font != nil {
|
||||||
attributedString.addAttribute(.font, value: font as Any, range: range)
|
attributedString.addAttribute(.font, value: font as Any, range: range)
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|||||||
@ -89,7 +89,7 @@ public typealias CoreObjectActionLoadPresentDelegate = MVMCoreActionDelegateProt
|
|||||||
//------------------------------------------------------
|
//------------------------------------------------------
|
||||||
|
|
||||||
public init() {
|
public init() {
|
||||||
super.init(frame: CGRect.zero)
|
super.init(frame: .zero)
|
||||||
setup()
|
setup()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,14 +104,14 @@ public typealias CoreObjectActionLoadPresentDelegate = MVMCoreActionDelegateProt
|
|||||||
}
|
}
|
||||||
|
|
||||||
public init(frontText: String?, actionText: String?, backText: String?, actionMap: [AnyHashable: Any]?, additionalData: [AnyHashable: Any]?, actionDelegate delegate: ActionObjectDelegate?, buttonDelegate: ButtonObjectDelegate?) {
|
public init(frontText: String?, actionText: String?, backText: String?, actionMap: [AnyHashable: Any]?, additionalData: [AnyHashable: Any]?, actionDelegate delegate: ActionObjectDelegate?, buttonDelegate: ButtonObjectDelegate?) {
|
||||||
super.init(frame: CGRect.zero)
|
super.init(frame: .zero)
|
||||||
|
|
||||||
setFrontText(frontText, actionText: actionText, actionMap: actionMap, backText: backText, additionalData: additionalData, delegate: delegate, buttonDelegate: buttonDelegate)
|
setFrontText(frontText, actionText: actionText, actionMap: actionMap, backText: backText, additionalData: additionalData, delegate: delegate, buttonDelegate: buttonDelegate)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - legacy
|
// MARK: - legacy
|
||||||
public init(frontText: String?, actionText: String?, backText: String?, actionBlock block: ActionBlock?) {
|
public init(frontText: String?, actionText: String?, backText: String?, actionBlock block: ActionBlock?) {
|
||||||
super.init(frame: CGRect.zero)
|
super.init(frame: .zero)
|
||||||
|
|
||||||
self.frontText = frontText
|
self.frontText = frontText
|
||||||
self.actionText = actionText
|
self.actionText = actionText
|
||||||
|
|||||||
@ -7,8 +7,6 @@
|
|||||||
// Copyright © 2019 Verizon Wireless. All rights reserved.
|
// Copyright © 2019 Verizon Wireless. All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
import MVMCoreUI
|
|
||||||
|
|
||||||
|
|
||||||
@objc open class LabelWithoutAccessibilityTraits: Label {
|
@objc open class LabelWithoutAccessibilityTraits: Label {
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user