Updated constraints. Dried up code. Address rightLabel issues when using preferredMaxLayout.
This commit is contained in:
parent
80dc8ea1fd
commit
52bfb1a8d1
@ -21,9 +21,6 @@ import Foundation
|
||||
// MARK: - Constraints
|
||||
//------------------------------------------------------
|
||||
|
||||
var leftTextWidth: NSLayoutConstraint?
|
||||
var rightTextWidth: NSLayoutConstraint?
|
||||
|
||||
var rightTextLabelLeading: NSLayoutConstraint?
|
||||
var leftTextLabelTrailing: NSLayoutConstraint?
|
||||
|
||||
@ -75,6 +72,8 @@ import Foundation
|
||||
// Resolves text layout issues found between both dynamically sized labels, number is not exact but performs as required.
|
||||
if leftTextLabel.hasText && rightTextLabel.hasText {
|
||||
rightTextLabel.preferredMaxLayoutWidth = floor((size - 16) * 0.4)
|
||||
} else if rightTextLabel.hasText {
|
||||
rightTextLabel.preferredMaxLayoutWidth = 0.0
|
||||
}
|
||||
}
|
||||
|
||||
@ -107,13 +106,13 @@ import Foundation
|
||||
|
||||
bottomAnchor.constraint(greaterThanOrEqualTo: rightTextLabel.bottomAnchor).isActive = true
|
||||
|
||||
leftTextWidth = leftTextLabel.widthAnchor.constraint(greaterThanOrEqualTo: layoutMarginsGuide.widthAnchor, multiplier: 0.6)
|
||||
leftTextWidth?.priority = UILayoutPriority(rawValue: 995)
|
||||
leftTextWidth?.isActive = true
|
||||
let leftTextWidth = leftTextLabel.widthAnchor.constraint(greaterThanOrEqualTo: layoutMarginsGuide.widthAnchor, multiplier: 0.6)
|
||||
leftTextWidth.priority = UILayoutPriority(rawValue: 995)
|
||||
leftTextWidth.isActive = true
|
||||
|
||||
rightTextWidth = rightTextLabel.widthAnchor.constraint(lessThanOrEqualTo: layoutMarginsGuide.widthAnchor, multiplier: 0.4)
|
||||
rightTextWidth?.priority = UILayoutPriority(rawValue: 906)
|
||||
rightTextWidth?.isActive = true
|
||||
let rightTextWidth = rightTextLabel.widthAnchor.constraint(lessThanOrEqualTo: layoutMarginsGuide.widthAnchor, multiplier: 0.4)
|
||||
rightTextWidth.priority = UILayoutPriority(rawValue: 906)
|
||||
rightTextWidth.isActive = true
|
||||
|
||||
leftTextLabel.setContentHuggingPriority(UILayoutPriority(rawValue: 901), for: .horizontal)
|
||||
rightTextLabel.setContentHuggingPriority(UILayoutPriority(rawValue: 902), for: .horizontal)
|
||||
@ -128,25 +127,29 @@ import Foundation
|
||||
|
||||
private func constrainLeftLabel() {
|
||||
|
||||
rightTextLabelLeading?.isActive = false
|
||||
leftTextLabelTrailing?.isActive = false
|
||||
deactivateMiddleConstraint()
|
||||
leftTextLabelTrailing = layoutMarginsGuide.trailingAnchor.constraint(equalTo: leftTextLabel.trailingAnchor)
|
||||
leftTextLabelTrailing?.isActive = true
|
||||
}
|
||||
|
||||
private func constrainRightLabel() {
|
||||
|
||||
rightTextLabelLeading?.isActive = false
|
||||
deactivateMiddleConstraint()
|
||||
rightTextLabelLeading = rightTextLabel.leadingAnchor.constraint(equalTo: layoutMarginsGuide.leadingAnchor)
|
||||
rightTextLabelLeading?.isActive = true
|
||||
}
|
||||
|
||||
override open func resetConstraints() {
|
||||
super.resetConstraints()
|
||||
override open func reset() {
|
||||
super.reset()
|
||||
|
||||
deactivateMiddleConstraint()
|
||||
constrainBothLabels()
|
||||
}
|
||||
|
||||
private func deactivateMiddleConstraint() {
|
||||
|
||||
leftTextLabelTrailing?.isActive = false
|
||||
rightTextLabelLeading?.isActive = false
|
||||
constrainBothLabels()
|
||||
}
|
||||
|
||||
//------------------------------------------------------
|
||||
|
||||
Loading…
Reference in New Issue
Block a user