Changed the way LeftRightLabelView works.
This commit is contained in:
parent
efec81871c
commit
c884b97fff
@ -14,19 +14,8 @@ import Foundation
|
|||||||
// MARK: - Properties
|
// MARK: - Properties
|
||||||
//------------------------------------------------------
|
//------------------------------------------------------
|
||||||
|
|
||||||
var title: Label?
|
var leftText: Label?
|
||||||
var message: Label?
|
var rightText: Label?
|
||||||
var detail: Label?
|
|
||||||
|
|
||||||
var titleWidth: NSLayoutConstraint?
|
|
||||||
var messageWidth: NSLayoutConstraint?
|
|
||||||
var detailWidth: NSLayoutConstraint?
|
|
||||||
|
|
||||||
var messageTrail: NSLayoutConstraint?
|
|
||||||
var titleTrail: NSLayoutConstraint?
|
|
||||||
|
|
||||||
var titleDetailBaseline: NSLayoutConstraint?
|
|
||||||
var messageDetailBaseline: NSLayoutConstraint?
|
|
||||||
|
|
||||||
//------------------------------------------------------
|
//------------------------------------------------------
|
||||||
// MARK: - Initialization
|
// MARK: - Initialization
|
||||||
@ -51,126 +40,80 @@ import Foundation
|
|||||||
|
|
||||||
override open func setupView() {
|
override open func setupView() {
|
||||||
super.setupView()
|
super.setupView()
|
||||||
|
|
||||||
translatesAutoresizingMaskIntoConstraints = false
|
translatesAutoresizingMaskIntoConstraints = false
|
||||||
defaultState()
|
defaultState()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//------------------------------------------------------
|
||||||
|
// MARK: - View Lifecycle
|
||||||
|
//------------------------------------------------------
|
||||||
|
|
||||||
|
override open func updateView(_ size: CGFloat) {
|
||||||
|
super.updateView(size)
|
||||||
|
|
||||||
|
leftText?.updateView(size)
|
||||||
|
rightText?.updateView(size)
|
||||||
|
|
||||||
|
layoutIfNeeded()
|
||||||
|
layoutSubviews()
|
||||||
|
}
|
||||||
|
|
||||||
//------------------------------------------------------
|
//------------------------------------------------------
|
||||||
// MARK: - Setup
|
// MARK: - Setup
|
||||||
//------------------------------------------------------
|
//------------------------------------------------------
|
||||||
|
|
||||||
override open func updateView(_ size: CGFloat) {
|
|
||||||
super.updateView(size)
|
|
||||||
|
|
||||||
title?.updateView(size)
|
|
||||||
message?.updateView(size)
|
|
||||||
detail?.updateView(size)
|
|
||||||
|
|
||||||
if let titleText = title?.text, let messageText = message?.text, titleText.isEmpty && messageText.isEmpty {
|
|
||||||
detailWidth?.constant = size
|
|
||||||
detail?.bottomAnchor.constraint(equalTo: bottomAnchor, constant: -PaddingTwo).isActive = true
|
|
||||||
titleDetailBaseline?.isActive = false
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if let detailText = detail?.text, detailText.isEmpty {
|
|
||||||
messageTrail?.isActive = false
|
|
||||||
titleTrail?.isActive = false
|
|
||||||
message?.trailingAnchor.constraint(equalTo: trailingAnchor).isActive = true
|
|
||||||
title?.trailingAnchor.constraint(equalTo: trailingAnchor).isActive = true
|
|
||||||
detailWidth?.constant = 0
|
|
||||||
titleWidth?.constant = size
|
|
||||||
messageWidth?.constant = size
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if let titleText = title?.text, titleText.isEmpty {
|
|
||||||
messageWidth?.constant = size * 0.6 - PaddingOne
|
|
||||||
detailWidth?.constant = size * 0.2
|
|
||||||
titleWidth?.constant = 0
|
|
||||||
titleDetailBaseline?.isActive = false
|
|
||||||
messageDetailBaseline?.isActive = true
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if let messageText = message?.text, messageText.isEmpty {
|
|
||||||
titleWidth?.constant = size * 0.6 - PaddingOne
|
|
||||||
detailWidth?.constant = size * 0.2
|
|
||||||
messageWidth?.constant = 0
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
titleWidth?.constant = size * 0.6 - PaddingOne
|
|
||||||
messageWidth?.constant = size * 0.6 - PaddingOne
|
|
||||||
detailWidth?.constant = size * 0.2
|
|
||||||
}
|
|
||||||
|
|
||||||
func defaultState() {
|
func defaultState() {
|
||||||
|
|
||||||
if title == nil && message == nil && detail == nil {
|
if leftText == nil && rightText == nil {
|
||||||
|
|
||||||
let title = Label.commonLabelB1(true)
|
let leftText = Label.commonLabelB1(true)
|
||||||
let message = Label.commonLabelB2(true)
|
let rightText = Label.commonLabelB1(true)
|
||||||
let detail = Label.commonLabelB1(true)
|
|
||||||
|
|
||||||
self.title = title
|
self.leftText = leftText
|
||||||
self.message = message
|
self.rightText = rightText
|
||||||
self.detail = detail
|
|
||||||
|
|
||||||
addSubview(title)
|
addSubview(leftText)
|
||||||
addSubview(message)
|
addSubview(rightText)
|
||||||
addSubview(detail)
|
|
||||||
|
|
||||||
title.textAlignment = .left
|
leftText.textAlignment = .left
|
||||||
message.textAlignment = .left
|
rightText.textAlignment = .right
|
||||||
detail.textAlignment = .right
|
|
||||||
|
|
||||||
title.topAnchor.constraint(equalTo: topAnchor).isActive = true
|
// leftText.topAnchor.constraint(equalTo: topAnchor).isActive = true
|
||||||
title.leadingAnchor.constraint(equalTo: leadingAnchor).isActive = true
|
// leftText.leadingAnchor.constraint(equalTo: leadingAnchor).isActive = true
|
||||||
let titleTrail = title.trailingAnchor.constraint(greaterThanOrEqualTo: detail.leadingAnchor)
|
leftText.trailingAnchor.constraint(equalTo: rightText.leadingAnchor).isActive = true
|
||||||
titleTrail.isActive = true
|
|
||||||
|
|
||||||
message.topAnchor.constraint(equalTo: title.bottomAnchor).isActive = true
|
NSLayoutConstraint.constraintPinSubview(leftText, pinTop: true, pinBottom: false, pinLeft: true, pinRight: false)
|
||||||
message.leadingAnchor.constraint(equalTo: leadingAnchor).isActive = true
|
|
||||||
message.bottomAnchor.constraint(equalTo: bottomAnchor).isActive = true
|
|
||||||
let messageTrail = message.trailingAnchor.constraint(greaterThanOrEqualTo: detail.leadingAnchor)
|
|
||||||
messageTrail.isActive = true
|
|
||||||
|
|
||||||
detail.topAnchor.constraint(equalTo: topAnchor).isActive = true
|
let leftTextBottom = leftText.bottomAnchor.constraint(equalTo: bottomAnchor)
|
||||||
detail.trailingAnchor.constraint(equalTo: trailingAnchor).isActive = true
|
leftTextBottom.priority = UILayoutPriority(249)
|
||||||
|
leftTextBottom.isActive = true
|
||||||
|
bottomAnchor.constraint(greaterThanOrEqualTo: leftText.bottomAnchor).isActive = true
|
||||||
|
|
||||||
titleDetailBaseline = detail.firstBaselineAnchor.constraint(equalTo: title.firstBaselineAnchor)
|
// rightText.topAnchor.constraint(equalTo: topAnchor).isActive = true
|
||||||
titleDetailBaseline?.isActive = true
|
// rightText.trailingAnchor.constraint(equalTo: trailingAnchor).isActive = true
|
||||||
|
NSLayoutConstraint.constraintPinSubview(rightText, pinTop: true, pinBottom: false, pinLeft: false, pinRight: true)
|
||||||
|
|
||||||
messageDetailBaseline = detail.firstBaselineAnchor.constraint(equalTo: message.firstBaselineAnchor)
|
|
||||||
|
|
||||||
titleWidth = title.widthAnchor.constraint(lessThanOrEqualToConstant: bounds.width * 0.8 - PaddingOne)
|
let rightTextBottom = rightText.bottomAnchor.constraint(equalTo: bottomAnchor)
|
||||||
titleWidth?.priority = UILayoutPriority(rawValue: 751)
|
rightTextBottom.priority = UILayoutPriority(rawValue: 249)
|
||||||
titleWidth?.isActive = true
|
rightTextBottom.isActive = true
|
||||||
|
bottomAnchor.constraint(greaterThanOrEqualTo: rightText.bottomAnchor).isActive = true
|
||||||
|
|
||||||
messageWidth = message.widthAnchor.constraint(lessThanOrEqualToConstant: bounds.width * 0.8 - PaddingOne)
|
let leftTextWidth = leftText.widthAnchor.constraint(equalTo: widthAnchor, multiplier: 0.7)
|
||||||
messageWidth?.priority = UILayoutPriority(rawValue: 750)
|
leftTextWidth.priority = UILayoutPriority(rawValue: 100)
|
||||||
messageWidth?.isActive = true
|
leftTextWidth.isActive = true
|
||||||
|
|
||||||
detailWidth = detail.widthAnchor.constraint(equalToConstant: bounds.width * 0.2)
|
// let rightTextWidth = rightText.widthAnchor.constraint(equalTo: widthAnchor, multiplier: 0.3)
|
||||||
detailWidth?.priority = UILayoutPriority(rawValue: 850)
|
// rightTextWidth.priority = UILayoutPriority(rawValue: 100)
|
||||||
detailWidth?.isActive = true
|
// rightTextWidth.isActive = true
|
||||||
|
|
||||||
title.setContentHuggingPriority(UILayoutPriority(rawValue: 251), for: .horizontal)
|
rightText.firstBaselineAnchor.constraint(equalTo: leftText.firstBaselineAnchor).isActive = true
|
||||||
title.setContentHuggingPriority(UILayoutPriority(rawValue: 249), for: .vertical)
|
|
||||||
title.setContentCompressionResistancePriority(UILayoutPriority(rawValue: 750), for: .horizontal)
|
|
||||||
title.setContentCompressionResistancePriority(UILayoutPriority(rawValue: 250), for: .vertical)
|
|
||||||
|
|
||||||
message.setContentHuggingPriority(UILayoutPriority(rawValue: 251), for: .horizontal)
|
leftText.setContentHuggingPriority(UILayoutPriority(rawValue: 801), for: .horizontal)
|
||||||
message.setContentHuggingPriority(UILayoutPriority(rawValue: 249), for: .vertical)
|
// leftText.setContentHuggingPriority(.required, for: .vertical)
|
||||||
message.setContentCompressionResistancePriority(UILayoutPriority(rawValue: 749), for: .horizontal)
|
|
||||||
message.setContentCompressionResistancePriority(UILayoutPriority(rawValue: 250), for: .vertical)
|
|
||||||
|
|
||||||
detail.setContentHuggingPriority(UILayoutPriority(rawValue: 750), for: .horizontal)
|
rightText.setContentHuggingPriority(UILayoutPriority(rawValue: 802), for: .horizontal)
|
||||||
detail.setContentHuggingPriority(UILayoutPriority(rawValue: 249), for: .vertical)
|
// rightText.setContentHuggingPriority(.required, for: .vertical)
|
||||||
detail.setContentCompressionResistancePriority(UILayoutPriority(rawValue: 750), for: .horizontal)
|
|
||||||
detail.setContentCompressionResistancePriority(UILayoutPriority(rawValue: 999), for: .vertical)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -178,9 +121,8 @@ import Foundation
|
|||||||
|
|
||||||
guard let dictionary = actionMap else { return }
|
guard let dictionary = actionMap else { return }
|
||||||
|
|
||||||
title?.setWithJSON(dictionary.optionalDictionaryForKey("title"), delegateObject: delegateObject as! MVMCoreUIDelegateObject, additionalData: additionalData)
|
leftText?.setWithJSON(dictionary.optionalDictionaryForKey("leftText"), delegateObject: delegateObject as? MVMCoreUIDelegateObject, additionalData: additionalData)
|
||||||
message?.setWithJSON(dictionary.optionalDictionaryForKey("message"), delegateObject: delegateObject as! MVMCoreUIDelegateObject, additionalData: additionalData)
|
rightText?.setWithJSON(dictionary.optionalDictionaryForKey("rightText"), delegateObject: delegateObject as? MVMCoreUIDelegateObject, additionalData: additionalData)
|
||||||
detail?.setWithJSON(dictionary.optionalDictionaryForKey("detail"), delegateObject: delegateObject as! MVMCoreUIDelegateObject, additionalData: additionalData)
|
|
||||||
|
|
||||||
if let backgroundColorHex = dictionary[KeyBackgroundColor] as? String {
|
if let backgroundColorHex = dictionary[KeyBackgroundColor] as? String {
|
||||||
backgroundColor = UIColor.mfGet(forHex: backgroundColorHex)
|
backgroundColor = UIColor.mfGet(forHex: backgroundColorHex)
|
||||||
@ -197,7 +139,11 @@ import Foundation
|
|||||||
}
|
}
|
||||||
|
|
||||||
open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: DelegateObject?, additionalData: [AnyHashable: Any]?) {
|
open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: DelegateObject?, additionalData: [AnyHashable: Any]?) {
|
||||||
super.setWithJSON(json, delegateObject: delegateObject as! MVMCoreUIDelegateObject, additionalData: additionalData)
|
super.setWithJSON(json, delegateObject: delegateObject as? MVMCoreUIDelegateObject, additionalData: additionalData)
|
||||||
setWithJSON(actionMap: json, delegateObject: delegateObject, additionalData: additionalData)
|
setWithJSON(actionMap: json, delegateObject: delegateObject, additionalData: additionalData)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
open override func needsToBeConstrained() -> Bool {
|
||||||
|
return true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user