I was able to set the constraints conditionally using the UIContentSizeCatagory.
- (void) setConstraints {
// Get the current size catagory of the text
UIContentSizeCategory catagory = self.traitCollection.preferredContentSizeCategory;
// Put the label on the trailing edge of the cell if the Dynamic Text size is less than large
if (catagory < UIContentSizeCategoryAccessibilityLarge) {
[NSLayoutConstraint activateConstraints:@[
// Cell Title Label
[self.themeColorLabel.leadingAnchor constraintEqualToAnchor:self.contentView.layoutMarginsGuide.leadingAnchor],
[self.themeColorLabel.trailingAnchor constraintEqualToAnchor:self.contentView.layoutMarginsGuide.trailingAnchor],
[self.themeColorLabel.topAnchor constraintEqualToAnchor: self.contentView.layoutMarginsGuide.topAnchor],
[self.themeColorLabel.bottomAnchor constraintEqualToAnchor: self.contentView.layoutMarginsGuide.bottomAnchor],
// Selected Theme Color Label
[self.selectedColorLabel.trailingAnchor constraintEqualToAnchor: self.contentView.layoutMarginsGuide.trailingAnchor],
[self.selectedColorLabel.topAnchor constraintEqualToAnchor: self.contentView.layoutMarginsGuide.topAnchor],
[self.selectedColorLabel.bottomAnchor constraintEqualToAnchor: self.contentView.layoutMarginsGuide.bottomAnchor],
]];
// Put the label below the title in sizes greater than large
} else {
[NSLayoutConstraint activateConstraints:@[
// Cell Title Label
[self.themeColorLabel.leadingAnchor constraintEqualToAnchor:self.contentView.layoutMarginsGuide.leadingAnchor],
[self.themeColorLabel.trailingAnchor constraintEqualToAnchor:self.contentView.layoutMarginsGuide.trailingAnchor],
[self.themeColorLabel.topAnchor constraintEqualToAnchor: self.contentView.layoutMarginsGuide.topAnchor],
// Selected Theme Color Label
[self.selectedColorLabel.leadingAnchor constraintEqualToAnchor: self.contentView.layoutMarginsGuide.leadingAnchor],
[self.selectedColorLabel.trailingAnchor constraintEqualToAnchor: self.contentView.layoutMarginsGuide.trailingAnchor],
[self.selectedColorLabel.topAnchor constraintEqualToAnchor: self.themeColorLabel.bottomAnchor],
[self.selectedColorLabel.bottomAnchor constraintEqualToAnchor: self.contentView.layoutMarginsGuide.bottomAnchor],
]];
}
}
Topic:
UI Frameworks
SubTopic:
UIKit
Tags: