Setting label alignment changes per title lock up alignment
This commit is contained in:
parent
4980874914
commit
8ca99f5802
@ -11,10 +11,15 @@
|
|||||||
// MARK: - Outlets
|
// MARK: - Outlets
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|
||||||
public let stack = Stack<StackModel>(frame: .zero)
|
|
||||||
public let eyebrow = Label(fontStyle: .RegularBodySmall)
|
public let eyebrow = Label(fontStyle: .RegularBodySmall)
|
||||||
public let headline = Label(fontStyle: .RegularBodySmall)
|
public let headline = Label(fontStyle: .RegularBodySmall)
|
||||||
public let body = Label(fontStyle: .RegularBodySmall)
|
public let body = Label(fontStyle: .RegularBodySmall)
|
||||||
|
public lazy var stack: Stack<StackModel> = {
|
||||||
|
return Stack<StackModel>.createStack(with: [(view: eyebrow, model: StackItemModel(horizontalAlignment: .fill)),
|
||||||
|
(view: headline, model: StackItemModel(horizontalAlignment: .fill)),
|
||||||
|
(view: body, model: StackItemModel(horizontalAlignment: .fill))],
|
||||||
|
axis: .vertical)
|
||||||
|
}()
|
||||||
|
|
||||||
var castModel: EyebrowHeadlineBodyModel? {
|
var castModel: EyebrowHeadlineBodyModel? {
|
||||||
get { return model as? EyebrowHeadlineBodyModel }
|
get { return model as? EyebrowHeadlineBodyModel }
|
||||||
@ -24,9 +29,8 @@
|
|||||||
// MARK: - Initialization
|
// MARK: - Initialization
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|
||||||
public convenience init(spacing: CGFloat) {
|
public convenience init() {
|
||||||
self.init(frame: .zero)
|
self.init(frame: .zero)
|
||||||
stack.stackModel?.spacing = spacing
|
|
||||||
stack.restack()
|
stack.restack()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,8 +40,6 @@
|
|||||||
|
|
||||||
open override func setupView() {
|
open override func setupView() {
|
||||||
super.setupView()
|
super.setupView()
|
||||||
stack.setAndCreateModel(with: [eyebrow, headline, body])
|
|
||||||
stack.stackModel?.spacing = 0
|
|
||||||
addSubview(stack)
|
addSubview(stack)
|
||||||
NSLayoutConstraint.constraintPinSubview(toSuperview: stack)
|
NSLayoutConstraint.constraintPinSubview(toSuperview: stack)
|
||||||
stack.restack()
|
stack.restack()
|
||||||
@ -56,9 +58,6 @@
|
|||||||
open override func reset() {
|
open override func reset() {
|
||||||
super.reset()
|
super.reset()
|
||||||
stack.reset()
|
stack.reset()
|
||||||
eyebrow.setFontStyle(.RegularBodySmall)
|
|
||||||
headline.setFontStyle(.RegularBodySmall)
|
|
||||||
body.setFontStyle(.RegularBodySmall)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -67,22 +66,24 @@
|
|||||||
|
|
||||||
open override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
|
open override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
|
||||||
super.set(with: model, delegateObject, additionalData)
|
super.set(with: model, delegateObject, additionalData)
|
||||||
setStyle(style: castModel?.style)
|
guard let model = model as? EyebrowHeadlineBodyModel else { return }
|
||||||
|
|
||||||
|
setStyle(style: model.style)
|
||||||
|
|
||||||
///Updating the text color
|
///Updating the text color
|
||||||
castModel?.eyebrow?.textColor = castModel?.headlineColor
|
model.eyebrow?.textColor = model.headlineColor
|
||||||
castModel?.headline.textColor = castModel?.headlineColor
|
model.headline.textColor = model.headlineColor
|
||||||
castModel?.body?.textColor = castModel?.bodyColor
|
model.body?.textColor = model.bodyColor
|
||||||
|
|
||||||
if let alignment = castModel?.alignment, let textAlignment = NSTextAlignment(rawValue: alignment.rawValue) {
|
if let textAlignment = NSTextAlignment(rawValue: model.alignment.rawValue) {
|
||||||
castModel?.eyebrow?.textAlignment = textAlignment
|
model.eyebrow?.textAlignment = textAlignment
|
||||||
castModel?.headline.textAlignment = textAlignment
|
model.headline.textAlignment = textAlignment
|
||||||
castModel?.body?.textAlignment = textAlignment
|
model.body?.textAlignment = textAlignment
|
||||||
}
|
}
|
||||||
|
|
||||||
stack.updateContainedMolecules(with: [castModel?.eyebrow,
|
stack.updateContainedMolecules(with: [model.eyebrow,
|
||||||
castModel?.headline,
|
model.headline,
|
||||||
castModel?.body],
|
model.body],
|
||||||
delegateObject, additionalData)
|
delegateObject, additionalData)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -100,7 +100,7 @@ public class EyebrowHeadlineBodyModel: MoleculeModelProtocol, ParentMoleculeMode
|
|||||||
|
|
||||||
switch self {
|
switch self {
|
||||||
case .small,.medium,.large:
|
case .small,.medium,.large:
|
||||||
return Padding.One
|
return Padding.Two
|
||||||
case .xlarge:
|
case .xlarge:
|
||||||
return Padding.Three
|
return Padding.Three
|
||||||
case .xxlarge:
|
case .xxlarge:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user