From a9539c6c896512cf566c7f134c7083fd716b7e01 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Tue, 20 Aug 2019 10:44:15 -0400 Subject: [PATCH] Fix competition --- MVMCoreUI/Molecules/CornerLabels.swift | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/MVMCoreUI/Molecules/CornerLabels.swift b/MVMCoreUI/Molecules/CornerLabels.swift index 2a2ad379..06917608 100644 --- a/MVMCoreUI/Molecules/CornerLabels.swift +++ b/MVMCoreUI/Molecules/CornerLabels.swift @@ -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