Fix competition
This commit is contained in:
parent
6a2405989d
commit
a9539c6c89
@ -88,9 +88,12 @@ import UIKit
|
||||
|
||||
topLabelsView.addSubview(topLeftLabel)
|
||||
topLabelsView.addSubview(topRightLabel)
|
||||
setCompetitionConstraints(topLeftLabel,topRightLabel)
|
||||
|
||||
bottomLabelsView.addSubview(bottomLeftLabel)
|
||||
bottomLabelsView.addSubview(bottomRightLabel)
|
||||
|
||||
setCompetitionConstraints(bottomLeftLabel,bottomRightLabel)
|
||||
|
||||
topLeftLabel.topAnchor.constraint(equalTo: topLabelsView.topAnchor).isActive = true
|
||||
topLeftLabel.leftAnchor.constraint(equalTo: topLabelsView.leftAnchor).isActive = true
|
||||
topLabelsView.bottomAnchor.constraint(greaterThanOrEqualTo: topLeftLabel.bottomAnchor).isActive = true
|
||||
@ -105,7 +108,9 @@ import UIKit
|
||||
constraint = topLabelsView.bottomAnchor.constraint(equalTo: topRightLabel.bottomAnchor)
|
||||
constraint.priority = topRightLabel.contentHuggingPriority(for: .vertical) - 10
|
||||
constraint.isActive = true
|
||||
|
||||
|
||||
topRightLabel.leftAnchor.constraint(equalTo: topLeftLabel.rightAnchor, constant: 16).isActive = true
|
||||
|
||||
bottomLeftLabel.topAnchor.constraint(equalTo: bottomLabelsView.topAnchor).isActive = true
|
||||
bottomLeftLabel.leftAnchor.constraint(equalTo: bottomLabelsView.leftAnchor).isActive = true
|
||||
bottomLabelsView.bottomAnchor.constraint(greaterThanOrEqualTo: bottomLeftLabel.bottomAnchor).isActive = true
|
||||
@ -120,6 +125,19 @@ import UIKit
|
||||
constraint = bottomLabelsView.bottomAnchor.constraint(equalTo: bottomRightLabel.bottomAnchor)
|
||||
constraint.priority = bottomRightLabel.contentHuggingPriority(for: .vertical) - 10
|
||||
constraint.isActive = true
|
||||
|
||||
bottomRightLabel.leftAnchor.constraint(greaterThanOrEqualTo: bottomLeftLabel.rightAnchor, constant: 16).isActive = true
|
||||
}
|
||||
|
||||
/// Sets the rules for the labels if they were to collide. The first view will take priority, but the second view has a minimum width when competing.
|
||||
func setCompetitionConstraints(_ view1: UIView,_ view2: UIView) {
|
||||
view1.setContentHuggingPriority(UILayoutPriority(rawValue: 700), for: .horizontal)
|
||||
view2.setContentHuggingPriority(UILayoutPriority(rawValue: 750), for: .horizontal)
|
||||
view1.setContentCompressionResistancePriority(UILayoutPriority(rawValue: 350), for: .horizontal)
|
||||
view2.setContentCompressionResistancePriority(UILayoutPriority(rawValue: 300), for: .horizontal)
|
||||
let width = view2.widthAnchor.constraint(equalTo: self.widthAnchor, multiplier: 0.40)
|
||||
width.priority = UILayoutPriority(rawValue: 400)
|
||||
width.isActive = true
|
||||
}
|
||||
|
||||
// MARK: - MVMCoreUIMoleculeViewProtocol
|
||||
|
||||
Loading…
Reference in New Issue
Block a user