fix alignments and defaults

This commit is contained in:
Pfeil, Scott Robert 2020-07-20 17:28:12 -04:00
parent 7f6ac77340
commit 0e3c08f341
2 changed files with 37 additions and 9 deletions

View File

@ -27,8 +27,8 @@ import Foundation
(view: subHeadline, model: StackItemModel()), (view: subHeadline, model: StackItemModel()),
(view: body, model: StackItemModel(horizontalAlignment: .fill))], (view: body, model: StackItemModel(horizontalAlignment: .fill))],
axis: .vertical, spacing: 0) axis: .vertical, spacing: 0)
stack = Stack<StackModel>.createStack(with: [(view: planLabel, model: StackItemModel(horizontalAlignment: .fill, verticalAlignment: .center)), stack = Stack<StackModel>.createStack(with: [(view: planLabel, model: StackItemModel(horizontalAlignment: .fill, verticalAlignment: .leading)),
(view: verticalStack, model: StackItemModel(horizontalAlignment: .fill))], (view: verticalStack, model: StackItemModel(horizontalAlignment: .fill, verticalAlignment: .leading))],
axis: .horizontal) axis: .horizontal)
super.init(frame: frame) super.init(frame: frame)
} }
@ -42,6 +42,8 @@ import Foundation
//------------------------------------------------------- //-------------------------------------------------------
open override func setupView() { open override func setupView() {
super.setupView() super.setupView()
planLabel.font = MFStyler.getMVA3FontSize(96, bold: true)
planLabel.standardFontSize = 96
addSubview(stack) addSubview(stack)
planLabel.setContentCompressionResistancePriority(.required, for: .horizontal) planLabel.setContentCompressionResistancePriority(.required, for: .horizontal)
planLabel.setContentHuggingPriority(.defaultHigh, for: .vertical) planLabel.setContentHuggingPriority(.defaultHigh, for: .vertical)
@ -51,6 +53,33 @@ import Foundation
verticalStack.restack() verticalStack.restack()
} }
public override func updateView(_ size: CGFloat) {
super.updateView(size)
stack.updateView(size)
cropPlanLabel()
}
/// Ensures the label is the size of capital letters.
public func cropPlanLabel() {
guard let text = planLabel.text else { return }
let attributedString = NSMutableAttributedString(attributedString: planLabel.attributedText ?? NSAttributedString(string: text))
let range = NSRange(location: 0, length: attributedString.length)
attributedString.removeAttribute(.paragraphStyle, range: range)
attributedString.removeAttribute(.baselineOffset, range: range)
// Accounts for the overshoot of non flat characters. 5% is typically the highest.
let overshoot: CGFloat = planLabel.font.pointSize * 0.05
// When messing with the maximum line height, the baseline needs to be adjusted.
let baseLineOffset = planLabel.font.descender + (overshoot / 2.0)
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.maximumLineHeight = planLabel.font.capHeight + overshoot
attributedString.addAttribute(.paragraphStyle, value: paragraphStyle, range: range)
attributedString.addAttribute(.baselineOffset, value: baseLineOffset, range: range)
planLabel.attributedText = attributedString
}
//---------------------------------------------------- //----------------------------------------------------
// MARK: - Molecule // MARK: - Molecule
//------------------------------------------------------ //------------------------------------------------------
@ -70,16 +99,14 @@ import Foundation
open override func reset() { open override func reset() {
super.reset() super.reset()
stack.reset()
planLabel.font = MFStyler.getMVA3FontSize(96, bold: true)
planLabel.standardFontSize = 96
headline.setFontStyle(.BoldTitleLarge) headline.setFontStyle(.BoldTitleLarge)
subHeadline.setFontStyle(.RegularTitleLarge) subHeadline.setFontStyle(.RegularTitleLarge)
body.setFontStyle(.RegularBodySmall) body.setFontStyle(.RegularBodySmall)
} }
public override func updateView(_ size: CGFloat) {
super.updateView(size)
planLabel.updateView(size)
}
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Accessibility // MARK: - Accessibility
//-------------------------------------------------- //--------------------------------------------------

View File

@ -29,6 +29,7 @@ public class LockupsPlanSMLXLModel: MoleculeModelProtocol {
self.headline = headline self.headline = headline
self.subHeadline = subHeadline self.subHeadline = subHeadline
self.body = body self.body = body
setDefaults()
} }
/// Defaults to set /// Defaults to set
@ -66,7 +67,7 @@ public class LockupsPlanSMLXLModel: MoleculeModelProtocol {
public func encode(to encoder: Encoder) throws { public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self) var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(moleculeName, forKey: .moleculeName) try container.encode(moleculeName, forKey: .moleculeName)
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
try container.encode(planLabel, forKey: .planLabel) try container.encode(planLabel, forKey: .planLabel)
try container.encode(headline, forKey: .headline) try container.encode(headline, forKey: .headline)