Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Max font size refactor #38

Merged
merged 2 commits into from
Aug 18, 2022
Merged

Max font size refactor #38

merged 2 commits into from
Aug 18, 2022

Conversation

AZielinsky95
Copy link
Contributor

This PR refactors dynamicTypeMaxSize to take in a CGFloat instead of a hardcoded enum value.

Other additions:

  • Font extension for scaledFont ( Needed for scaling up font within AttributedString builder )
  • Update init for NiceText with AttributedString
  • Update example project

It occurred to me while putting up this PR that another option we have for supporting DynamicTypeSize without having users input arbitrary values for their maxFont size is to simply apply the same increments/decrements to base font size as done by apple shown here. That way scaling aligns with how the OS handles it. Only problem there is if Apple ever makes adjustments to the table they would have to be reflected here as well.

Example:

extension DynamicTypeSize {
    static func getMaxFontSize(_ baseSize: CGFloat, dyamicTypeSizeMax: DynamicTypeSize) -> CGFloat {
        switch dyamicTypeSizeMax {
        case .xSmall:
            return baseSize - 3.0
        case .small:
            return baseSize - 2.0
        case .medium:
            return baseSize - 1.0
        case .large:
            return baseSize
        case .xLarge:
            return baseSize + 2.0
            etc..

Let me know what you think @brendanlensink

- Add font extension for scaledFont
- Update init for attributed string
Copy link
Collaborator

@brendanlensink brendanlensink left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛥️

@AZielinsky95 AZielinsky95 merged commit a859ac7 into main Aug 18, 2022
@AZielinsky95 AZielinsky95 deleted the az/dynamic-type branch August 18, 2022 18:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants