Label fix

This commit is contained in:
Pfeil, Scott Robert 2020-01-16 15:51:15 -05:00
parent 0529c9d357
commit 7d5bee5654
3 changed files with 28 additions and 9 deletions

View File

@ -244,10 +244,15 @@ public typealias ActionBlock = () -> ()
}
if let fontStyle = labelModel.fontStyle {
MFStyler.styleLabel(self, withStyle: fontStyle)
MFStyler.styleLabel(self, withStyle: fontStyle, genericScaling: false)
standardFontSize = font.pointSize
} else {
let fontSize = labelModel.fontSize
if let fontSize = fontSize {
standardFontSize = fontSize
}
if let fontName = labelModel.fontName {
font = MFFonts.mfFont(withName: fontName, size: fontSize ?? font.pointSize)
font = MFFonts.mfFont(withName: fontName, size: fontSize ?? standardFontSize)
} else if let fontSize = fontSize {
font = font.withSize(fontSize)
}
@ -262,9 +267,9 @@ public typealias ActionBlock = () -> ()
for attribute in attributes {
let range = NSRange(location: attribute.location, length: attribute.length)
switch attribute {
case let underLineAtt as LabelAttributeUnderlineModel:
case let _ as LabelAttributeUnderlineModel:
attributedString.addAttribute(.underlineStyle, value: NSUnderlineStyle.single.rawValue, range: range)
case let strikeAtt as LabelAttributeStrikeThroughModel:
case let _ as LabelAttributeStrikeThroughModel:
attributedString.addAttribute(.strikethroughStyle, value: NSUnderlineStyle.thick.rawValue, range: range)
attributedString.addAttribute(.baselineOffset, value: 0, range: range)
case let colorAtt as LabelAttributeColorModel:
@ -309,11 +314,17 @@ public typealias ActionBlock = () -> ()
}
}
case let actionAtt as LabelAttributeActionModel:
addTappableLinkAttribute(range: NSRange(location: range.location, length: range.length)) {
if let data = try? actionAtt.encode(using: JSONEncoder()), let actionMap = try? JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions.init()) as? [AnyHashable: Any] {
MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegateObject: delegateObject)
}
}
addActionAttributes(range: range, string: attributedString)
default:
continue
}
}
attributedText = attributedString
originalAttributedString = attributedText
hero = labelModel.hero
}

View File

@ -12,12 +12,21 @@ class LabelAttributeActionModel: LabelAttributeModel {
override public class var identifier: String {
return "action"
}
var action: ActionProtocol
required public init(from decoder: Decoder) throws {
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
action = try typeContainer.decodeModel(codingKey: .action, typeCodingKey: ActionCodingKey.actionType)
try super.init(from: decoder)
}
public override func encode(to encoder: Encoder) throws {
try super.encode(to: encoder)
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeModel(action, forKey: .action)
}
private enum CodingKeys: String, CodingKey {
case action
}
}

View File

@ -179,10 +179,9 @@ open class DoughnutChart: View {
let labelheight = labelContainer.frame.height/2
let padding = sizeObject.getValueBasedOnApplicationWidth()/2 - sqrt(pow(radius, 2) - pow(labelheight, 2))
labelContainer.leftPin?.constant = padding
labelContainer.rightPin?.constant = padding
labelContainer.topPin?.constant = max(radius - labelheight, labelheight)
labelContainer.bottomPin?.constant = max(radius - labelheight, labelheight)
labelContainerLeftConstraint?.constant = padding
labelContainerRightConstraint?.constant = padding
labelContainerTopConstraint?.constant = max(radius - labelheight, labelheight)
labelContainerBottomConstraint?.constant = max(radius - labelheight, labelheight)
}
}