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

Help: custom fonts for NodeTypes #39

Open
StanleyOned opened this issue Aug 30, 2022 · 2 comments
Open

Help: custom fonts for NodeTypes #39

StanleyOned opened this issue Aug 30, 2022 · 2 comments

Comments

@StanleyOned
Copy link

Hello contentful team,

I hope you guys are doing well, I've been wondering how or if I can provide my own fonts to specific labels/attributed string. I can't find any documentation about providing my own font styles / AttributedString to specific UILabel/Views

@kamila-and
Copy link

I haven't found a way and ended up forking the library and customising it to fit my needs, so I recommend just doing that

@oliveira-marcio
Copy link

I did that by overring the default font provider, for example:

    final class CustomFontProvider: FontProviding {
        var regular = Style.Fonts.lightBodyText // Just a regular UIFont kept in a static enum here
        var bold = Style.Fonts.bodyText
        var italic = Style.Fonts.italicLightBodyText
        var boldItalic = Style.Fonts.italicBodyText
        var headingFonts: HeadingFonts {
            .init(
                h1: Style.Fonts.subheaderText,
                h2: Style.Fonts.subheaderText,
                h3: Style.Fonts.leadText,
                h4: Style.Fonts.leadText,
                h5: Style.Fonts.leadText,
                h6: Style.Fonts.leadText
            )
        }
        var monospaced = Style.Fonts.lightBodyText
    }

Then I injected it into the renders provider when initializing the VC:

    init() {
        var configuration = DefaultRendererConfiguration()
        configuration.fontProvider = CustomFontProvider()
        let renderer = RichTextDocumentRenderer(
            configuration: configuration,
            nodeRenderers: DefaultRenderersProvider()
        )
        super.init(renderer: renderer, isScrollEnabled: false)
    }

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

No branches or pull requests

3 participants