Unnecessary import. Simplified code. Fixed font optional.
This commit is contained in:
parent
83dda81d55
commit
3d2059754c
@ -79,59 +79,59 @@ import MVMCore
|
|||||||
//------------------------------------------------------
|
//------------------------------------------------------
|
||||||
// MARK: - Functions
|
// MARK: - Functions
|
||||||
//------------------------------------------------------
|
//------------------------------------------------------
|
||||||
|
|
||||||
@objc public static func commonLabelH1(_ scale: Bool) -> Label {
|
@objc public static func commonLabelH1(_ scale: Bool) -> Label {
|
||||||
let label = Label.label()
|
let label = Label.label()
|
||||||
label.styleH1(scale)
|
label.styleH1(scale)
|
||||||
return label
|
return label
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc public static func commonLabelH2(_ scale: Bool) -> Label {
|
@objc public static func commonLabelH2(_ scale: Bool) -> Label {
|
||||||
let label = Label.label()
|
let label = Label.label()
|
||||||
label.styleH2(scale)
|
label.styleH2(scale)
|
||||||
return label
|
return label
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc public static func commonLabelH3(_ scale: Bool) -> Label {
|
@objc public static func commonLabelH3(_ scale: Bool) -> Label {
|
||||||
let label = Label.label()
|
let label = Label.label()
|
||||||
label.styleH3(scale)
|
label.styleH3(scale)
|
||||||
return label
|
return label
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc public static func commonLabelH32(_ scale: Bool) -> Label {
|
@objc public static func commonLabelH32(_ scale: Bool) -> Label {
|
||||||
let label = Label.label()
|
let label = Label.label()
|
||||||
label.styleH32(scale)
|
label.styleH32(scale)
|
||||||
return label
|
return label
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc public static func commonLabelB1(_ scale: Bool) -> Label {
|
@objc public static func commonLabelB1(_ scale: Bool) -> Label {
|
||||||
let label = Label.label()
|
let label = Label.label()
|
||||||
label.styleB1(scale)
|
label.styleB1(scale)
|
||||||
return label
|
return label
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc public static func commonLabelB2(_ scale: Bool) -> Label {
|
@objc public static func commonLabelB2(_ scale: Bool) -> Label {
|
||||||
let label = Label.label()
|
let label = Label.label()
|
||||||
label.styleB2(scale)
|
label.styleB2(scale)
|
||||||
return label
|
return label
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc public static func commonLabelB3(_ scale: Bool) -> Label {
|
@objc public static func commonLabelB3(_ scale: Bool) -> Label {
|
||||||
let label = Label.label()
|
let label = Label.label()
|
||||||
label.styleB3(scale)
|
label.styleB3(scale)
|
||||||
return label
|
return label
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc public static func commonLabelB20(_ scale: Bool) -> Label {
|
@objc public static func commonLabelB20(_ scale: Bool) -> Label {
|
||||||
let label = Label.label()
|
let label = Label.label()
|
||||||
label.styleB20(scale)
|
label.styleB20(scale)
|
||||||
return label
|
return label
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc open class func label() -> Label {
|
@objc open class func label() -> Label {
|
||||||
return Label(frame: CGRect.zero)
|
return Label(frame: CGRect.zero)
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------
|
//------------------------------------------------------
|
||||||
// MARK: - Functions
|
// MARK: - Functions
|
||||||
//------------------------------------------------------
|
//------------------------------------------------------
|
||||||
@ -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)
|
||||||
}
|
}
|
||||||
|
|
||||||
attributedString.addAttribute(.font, value: font as Any, range: range)
|
if font != nil {
|
||||||
|
attributedString.addAttribute(.font, value: font as Any, range: range)
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -234,7 +235,7 @@ import MVMCore
|
|||||||
MFStyler.styleLabelH3(self, genericScaling: false)
|
MFStyler.styleLabelH3(self, genericScaling: false)
|
||||||
setScale(scale)
|
setScale(scale)
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc public func styleH32(_ scale: Bool) {
|
@objc public func styleH32(_ scale: Bool) {
|
||||||
MFStyler.styleLabelH32(self, genericScaling: false)
|
MFStyler.styleLabelH32(self, genericScaling: false)
|
||||||
setScale(scale)
|
setScale(scale)
|
||||||
@ -310,17 +311,17 @@ import MVMCore
|
|||||||
@objc public func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: DelegateObject?, additionalData: [AnyHashable: Any]?) {
|
@objc public func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: DelegateObject?, additionalData: [AnyHashable: Any]?) {
|
||||||
Label.setUILabel(self, withJSON: json, delegate: delegateObject, additionalData: additionalData)
|
Label.setUILabel(self, withJSON: json, delegate: delegateObject, additionalData: additionalData)
|
||||||
|
|
||||||
// guard let dictionary = json else { return }
|
// guard let dictionary = json else { return }
|
||||||
|
|
||||||
/*
|
/*
|
||||||
if let numberOfLinesCount = dictionary["numberOfLines"] as? Int {
|
if let numberOfLinesCount = dictionary["numberOfLines"] as? Int {
|
||||||
numberOfLines = numberOfLinesCount
|
numberOfLines = numberOfLinesCount
|
||||||
}
|
}
|
||||||
|
|
||||||
if let lineBreakModeValue = dictionary["lineBreakMode"] as? Int, let brakMode = NSLineBreakMode(rawValue: lineBreakModeValue) {
|
if let lineBreakModeValue = dictionary["lineBreakMode"] as? Int, let brakMode = NSLineBreakMode(rawValue: lineBreakModeValue) {
|
||||||
lineBreakMode = brakMode
|
lineBreakMode = brakMode
|
||||||
}
|
}
|
||||||
|
|
||||||
0 byWordWrapping // Wrap at word boundaries, default
|
0 byWordWrapping // Wrap at word boundaries, default
|
||||||
1 byCharWrapping // Wrap at character boundaries
|
1 byCharWrapping // Wrap at character boundaries
|
||||||
2 byClipping // Simply clip
|
2 byClipping // Simply clip
|
||||||
|
|||||||
@ -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
|
||||||
@ -413,7 +413,7 @@ public typealias CoreObjectActionLoadPresentDelegate = MVMCoreActionDelegateProt
|
|||||||
actionableTuple.end = secondHalf[1]
|
actionableTuple.end = secondHalf[1]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return actionableTuple
|
return actionableTuple
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -6,9 +6,7 @@
|
|||||||
// Converted by Christiano, Kevin on 4/15/19.
|
// Converted by Christiano, Kevin on 4/15/19.
|
||||||
// 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