Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Not work Dynamic Size for Font #11

Closed
alexflm opened this issue Aug 17, 2021 · 2 comments
Closed

Not work Dynamic Size for Font #11

alexflm opened this issue Aug 17, 2021 · 2 comments
Labels
bug Something isn't working

Comments

@alexflm
Copy link

alexflm commented Aug 17, 2021

Good afternoon!
Thanks for your library, it helped a lot in development. But I noticed that if you change the font size in the application, AttibutedText will not change size, to fix this you need to add this line:

textView.adjustsFontForContentSizeCategory = true

@gonzalezreal
Copy link
Owner

Hi,
Thanks for the feedback! I will have a look at this as soon as I can.

@gonzalezreal gonzalezreal added the bug Something isn't working label Aug 19, 2021
@gonzalezreal
Copy link
Owner

Hi again,
Turns out adjustsFontForContentSizeCategory is not working as expected. As a workaround, you can make your view update when the content size category changes.

struct ContentView: View {
    @Environment(\.sizeCategory) private var sizeCategory: ContentSizeCategory
    
    var text: NSAttributedString {
        let result = NSMutableAttributedString(string: "Hello world!")
        
        result.addAttributes(
            [.font: UIFont.preferredFont(forTextStyle: .title1)],
            range: NSRange(location: 0, length: 5)
        )
        
        result.addAttributes(
            [.font: UIFont.preferredFont(forTextStyle: .headline)],
            range: NSRange(location: 6, length: 6)
        )
        
        return result
    }
    
    var body: some View {
        AttributedText(text)
            .padding()
    }
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants