fix alignments and defaults
This commit is contained in:
parent
7f6ac77340
commit
0e3c08f341
@ -27,8 +27,8 @@ import Foundation
|
||||
(view: subHeadline, model: StackItemModel()),
|
||||
(view: body, model: StackItemModel(horizontalAlignment: .fill))],
|
||||
axis: .vertical, spacing: 0)
|
||||
stack = Stack<StackModel>.createStack(with: [(view: planLabel, model: StackItemModel(horizontalAlignment: .fill, verticalAlignment: .center)),
|
||||
(view: verticalStack, model: StackItemModel(horizontalAlignment: .fill))],
|
||||
stack = Stack<StackModel>.createStack(with: [(view: planLabel, model: StackItemModel(horizontalAlignment: .fill, verticalAlignment: .leading)),
|
||||
(view: verticalStack, model: StackItemModel(horizontalAlignment: .fill, verticalAlignment: .leading))],
|
||||
axis: .horizontal)
|
||||
super.init(frame: frame)
|
||||
}
|
||||
@ -42,6 +42,8 @@ import Foundation
|
||||
//-------------------------------------------------------
|
||||
open override func setupView() {
|
||||
super.setupView()
|
||||
planLabel.font = MFStyler.getMVA3FontSize(96, bold: true)
|
||||
planLabel.standardFontSize = 96
|
||||
addSubview(stack)
|
||||
planLabel.setContentCompressionResistancePriority(.required, for: .horizontal)
|
||||
planLabel.setContentHuggingPriority(.defaultHigh, for: .vertical)
|
||||
@ -51,6 +53,33 @@ import Foundation
|
||||
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
|
||||
//------------------------------------------------------
|
||||
@ -70,16 +99,14 @@ import Foundation
|
||||
|
||||
open override func reset() {
|
||||
super.reset()
|
||||
stack.reset()
|
||||
planLabel.font = MFStyler.getMVA3FontSize(96, bold: true)
|
||||
planLabel.standardFontSize = 96
|
||||
headline.setFontStyle(.BoldTitleLarge)
|
||||
subHeadline.setFontStyle(.RegularTitleLarge)
|
||||
body.setFontStyle(.RegularBodySmall)
|
||||
}
|
||||
|
||||
public override func updateView(_ size: CGFloat) {
|
||||
super.updateView(size)
|
||||
planLabel.updateView(size)
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Accessibility
|
||||
//--------------------------------------------------
|
||||
|
||||
@ -29,6 +29,7 @@ public class LockupsPlanSMLXLModel: MoleculeModelProtocol {
|
||||
self.headline = headline
|
||||
self.subHeadline = subHeadline
|
||||
self.body = body
|
||||
setDefaults()
|
||||
}
|
||||
|
||||
/// Defaults to set
|
||||
@ -66,7 +67,7 @@ public class LockupsPlanSMLXLModel: MoleculeModelProtocol {
|
||||
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
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.encode(planLabel, forKey: .planLabel)
|
||||
try container.encode(headline, forKey: .headline)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user