Unnecessary import. Simplified code. Fixed font optional.

This commit is contained in:
Christiano, Kevin 2019-04-23 11:20:05 -04:00
parent 83dda81d55
commit 3d2059754c
3 changed files with 58 additions and 59 deletions

View File

@ -79,59 +79,59 @@ import MVMCore
//------------------------------------------------------
// MARK: - Functions
//------------------------------------------------------
@objc public static func commonLabelH1(_ scale: Bool) -> Label {
@objc public static func commonLabelH1(_ scale: Bool) -> Label {
let label = Label.label()
label.styleH1(scale)
return label
}
@objc public static func commonLabelH2(_ scale: Bool) -> Label {
}
@objc public static func commonLabelH2(_ scale: Bool) -> Label {
let label = Label.label()
label.styleH2(scale)
return label
}
@objc public static func commonLabelH3(_ scale: Bool) -> Label {
}
@objc public static func commonLabelH3(_ scale: Bool) -> Label {
let label = Label.label()
label.styleH3(scale)
return label
}
@objc public static func commonLabelH32(_ scale: Bool) -> Label {
}
@objc public static func commonLabelH32(_ scale: Bool) -> Label {
let label = Label.label()
label.styleH32(scale)
return label
}
@objc public static func commonLabelB1(_ scale: Bool) -> Label {
}
@objc public static func commonLabelB1(_ scale: Bool) -> Label {
let label = Label.label()
label.styleB1(scale)
return label
}
@objc public static func commonLabelB2(_ scale: Bool) -> Label {
}
@objc public static func commonLabelB2(_ scale: Bool) -> Label {
let label = Label.label()
label.styleB2(scale)
return label
}
@objc public static func commonLabelB3(_ scale: Bool) -> Label {
}
@objc public static func commonLabelB3(_ scale: Bool) -> Label {
let label = Label.label()
label.styleB3(scale)
return label
}
@objc public static func commonLabelB20(_ scale: Bool) -> Label {
}
@objc public static func commonLabelB20(_ scale: Bool) -> Label {
let label = Label.label()
label.styleB20(scale)
return label
}
@objc open class func label() -> Label {
}
@objc open class func label() -> Label {
return Label(frame: CGRect.zero)
}
}
//------------------------------------------------------
// MARK: - Functions
//------------------------------------------------------
@ -168,20 +168,20 @@ import MVMCore
label.accessibilityLabel = json?.optionalStringForKey("accessibilityText")
let fontSize = json?.floatForKey("fontSize") ?? 0.0
let fontSize = json?["fontSize"] as? CGFloat
if let fontName = json?.optionalStringForKey("fontName") {
label.font = MFFonts.mfFont(withName: fontName, size: fontSize == 0.0 ? label.font.pointSize : CGFloat(fontSize))
} else {
label.font = label.font.withSize(CGFloat(fontSize))
label.font = MFFonts.mfFont(withName: fontName, size: fontSize ?? label.font.pointSize)
} else if let fontSize = fontSize {
label.font = label.font.withSize(fontSize)
}
if let attributes = json?.arrayForKey("attributes"), let labelText = label.text {
let attributedString = NSMutableAttributedString(string: labelText, attributes: [NSAttributedString.Key.font: label.font as Any,
NSAttributedString.Key.foregroundColor: label.textColor as Any])
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 }
@ -197,17 +197,18 @@ import MVMCore
attributedString.addAttribute(.foregroundColor, value: UIColor.mfGet(forHex: colorHex), range: range)
}
case "font":
let fontSize = attribute.floatForKey("size")
let font: UIFont?
let fontSize = json?["size"] as? CGFloat
var font: UIFont?
if let fontName = attribute.optionalStringForKey("name"), !fontName.isEmpty {
font = MFFonts.mfFont(withName: fontName, size: fontSize != 0.0 ? CGFloat(fontSize) : CGFloat(label.font.pointSize))
} else {
font = label.font.withSize(CGFloat(fontSize))
if let fontName = attribute.optionalStringForKey("name") {
font = MFFonts.mfFont(withName: fontName, size: fontSize ?? label.font.pointSize)
} else if let fontSize = 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:
continue
}
@ -234,7 +235,7 @@ import MVMCore
MFStyler.styleLabelH3(self, genericScaling: false)
setScale(scale)
}
@objc public func styleH32(_ scale: Bool) {
MFStyler.styleLabelH32(self, genericScaling: false)
setScale(scale)
@ -310,17 +311,17 @@ import MVMCore
@objc public func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: DelegateObject?, additionalData: [AnyHashable: Any]?) {
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 {
numberOfLines = numberOfLinesCount
}
if let lineBreakModeValue = dictionary["lineBreakMode"] as? Int, let brakMode = NSLineBreakMode(rawValue: lineBreakModeValue) {
lineBreakMode = brakMode
}
if let numberOfLinesCount = dictionary["numberOfLines"] as? Int {
numberOfLines = numberOfLinesCount
}
if let lineBreakModeValue = dictionary["lineBreakMode"] as? Int, let brakMode = NSLineBreakMode(rawValue: lineBreakModeValue) {
lineBreakMode = brakMode
}
0 byWordWrapping // Wrap at word boundaries, default
1 byCharWrapping // Wrap at character boundaries
2 byClipping // Simply clip

View File

@ -89,7 +89,7 @@ public typealias CoreObjectActionLoadPresentDelegate = MVMCoreActionDelegateProt
//------------------------------------------------------
public init() {
super.init(frame: CGRect.zero)
super.init(frame: .zero)
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?) {
super.init(frame: CGRect.zero)
super.init(frame: .zero)
setFrontText(frontText, actionText: actionText, actionMap: actionMap, backText: backText, additionalData: additionalData, delegate: delegate, buttonDelegate: buttonDelegate)
}
// MARK: - legacy
public init(frontText: String?, actionText: String?, backText: String?, actionBlock block: ActionBlock?) {
super.init(frame: CGRect.zero)
super.init(frame: .zero)
self.frontText = frontText
self.actionText = actionText
@ -413,7 +413,7 @@ public typealias CoreObjectActionLoadPresentDelegate = MVMCoreActionDelegateProt
actionableTuple.end = secondHalf[1]
}
}
return actionableTuple
}

View File

@ -6,9 +6,7 @@
// Converted by Christiano, Kevin on 4/15/19.
// Copyright © 2019 Verizon Wireless. All rights reserved.
//
import MVMCoreUI
@objc open class LabelWithoutAccessibilityTraits: Label {