I would definitely like to use dynamic type as much as possible within an iOS app - I like the idea that the user can choose whatever size they prefer.
However, when the font size is set to some of the lower values, the app ends up looking frankly ridiculous, with tiny text at one side and a whole load of white space. Personally, I have my phone set to the smallest font (it seems perfect for messages and emails) but would beyond balk at the layout that leads to in this app. (Because of the fixed size of an image it is not possible to fix this layout for smaller fonts.)
In short, I'm looking for a way to set a minimum font size for Body text, or for a specific label regardless of what dynamic type says, or a way to block certain dynamic type levels.
Try this to set minimum font size for label supporting dynamic type.
In Viewdidload method -
NotificationCenter.default.addObserver(self, selector: #selector(self.handleDynamicTypeChange), name: NSNotification.Name.UIContentSizeCategoryDidChange, object: nil)
In handler method -
func handleDynamicTypeChange() {
print("size category changed to --->\(UIApplication.shared.preferredContentSizeCategory)")
if (UIApplication.shared.preferredContentSizeCategory) == UIContentSizeCategory(rawValue: "UICTContentSizeCategoryXS") || (UIApplication.shared.preferredContentSizeCategory) == UIContentSizeCategory(rawValue: "UICTContentSizeCategoryS") {
dynamicLabel?.font.withSize(12.0)
}
else {
dynamicLabel?.font = UIFont.preferredFont(forTextStyle: .body)
}
}