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
|
// MARK: - Constraints
|
||||||
//------------------------------------------------------
|
//------------------------------------------------------
|
||||||
|
|
||||||
var leftTextWidth: NSLayoutConstraint?
|
|
||||||
var rightTextWidth: NSLayoutConstraint?
|
|
||||||
|
|
||||||
var rightTextLabelLeading: NSLayoutConstraint?
|
var rightTextLabelLeading: NSLayoutConstraint?
|
||||||
var leftTextLabelTrailing: 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.
|
// Resolves text layout issues found between both dynamically sized labels, number is not exact but performs as required.
|
||||||
if leftTextLabel.hasText && rightTextLabel.hasText {
|
if leftTextLabel.hasText && rightTextLabel.hasText {
|
||||||
rightTextLabel.preferredMaxLayoutWidth = floor((size - 16) * 0.4)
|
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
|
bottomAnchor.constraint(greaterThanOrEqualTo: rightTextLabel.bottomAnchor).isActive = true
|
||||||
|
|
||||||
leftTextWidth = leftTextLabel.widthAnchor.constraint(greaterThanOrEqualTo: layoutMarginsGuide.widthAnchor, multiplier: 0.6)
|
let leftTextWidth = leftTextLabel.widthAnchor.constraint(greaterThanOrEqualTo: layoutMarginsGuide.widthAnchor, multiplier: 0.6)
|
||||||
leftTextWidth?.priority = UILayoutPriority(rawValue: 995)
|
leftTextWidth.priority = UILayoutPriority(rawValue: 995)
|
||||||
leftTextWidth?.isActive = true
|
leftTextWidth.isActive = true
|
||||||
|
|
||||||
rightTextWidth = rightTextLabel.widthAnchor.constraint(lessThanOrEqualTo: layoutMarginsGuide.widthAnchor, multiplier: 0.4)
|
let rightTextWidth = rightTextLabel.widthAnchor.constraint(lessThanOrEqualTo: layoutMarginsGuide.widthAnchor, multiplier: 0.4)
|
||||||
rightTextWidth?.priority = UILayoutPriority(rawValue: 906)
|
rightTextWidth.priority = UILayoutPriority(rawValue: 906)
|
||||||
rightTextWidth?.isActive = true
|
rightTextWidth.isActive = true
|
||||||
|
|
||||||
leftTextLabel.setContentHuggingPriority(UILayoutPriority(rawValue: 901), for: .horizontal)
|
leftTextLabel.setContentHuggingPriority(UILayoutPriority(rawValue: 901), for: .horizontal)
|
||||||
rightTextLabel.setContentHuggingPriority(UILayoutPriority(rawValue: 902), for: .horizontal)
|
rightTextLabel.setContentHuggingPriority(UILayoutPriority(rawValue: 902), for: .horizontal)
|
||||||
@ -128,25 +127,29 @@ import Foundation
|
|||||||
|
|
||||||
private func constrainLeftLabel() {
|
private func constrainLeftLabel() {
|
||||||
|
|
||||||
rightTextLabelLeading?.isActive = false
|
deactivateMiddleConstraint()
|
||||||
leftTextLabelTrailing?.isActive = false
|
|
||||||
leftTextLabelTrailing = layoutMarginsGuide.trailingAnchor.constraint(equalTo: leftTextLabel.trailingAnchor)
|
leftTextLabelTrailing = layoutMarginsGuide.trailingAnchor.constraint(equalTo: leftTextLabel.trailingAnchor)
|
||||||
leftTextLabelTrailing?.isActive = true
|
leftTextLabelTrailing?.isActive = true
|
||||||
}
|
}
|
||||||
|
|
||||||
private func constrainRightLabel() {
|
private func constrainRightLabel() {
|
||||||
|
|
||||||
rightTextLabelLeading?.isActive = false
|
deactivateMiddleConstraint()
|
||||||
rightTextLabelLeading = rightTextLabel.leadingAnchor.constraint(equalTo: layoutMarginsGuide.leadingAnchor)
|
rightTextLabelLeading = rightTextLabel.leadingAnchor.constraint(equalTo: layoutMarginsGuide.leadingAnchor)
|
||||||
rightTextLabelLeading?.isActive = true
|
rightTextLabelLeading?.isActive = true
|
||||||
}
|
}
|
||||||
|
|
||||||
override open func resetConstraints() {
|
override open func reset() {
|
||||||
super.resetConstraints()
|
super.reset()
|
||||||
|
|
||||||
|
deactivateMiddleConstraint()
|
||||||
|
constrainBothLabels()
|
||||||
|
}
|
||||||
|
|
||||||
|
private func deactivateMiddleConstraint() {
|
||||||
|
|
||||||
leftTextLabelTrailing?.isActive = false
|
leftTextLabelTrailing?.isActive = false
|
||||||
rightTextLabelLeading?.isActive = false
|
rightTextLabelLeading?.isActive = false
|
||||||
constrainBothLabels()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------
|
//------------------------------------------------------
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user