uias / Tabman

™️ A powerful paging view controller with interactive indicator bars
https://uias.github.io/Tabman
MIT License
2.84k stars 235 forks source link

Tabbar labels not updating according to set size in Settings #557

Closed mkoorn closed 3 years ago

mkoorn commented 3 years ago

New Issue Checklist

Issue Description

I am trying to get the label text sizes to update when the user changes in Settings->Accessibility->Display & Text size

Any idea how to force this?

msaps commented 3 years ago

@mkoorn the current built-in components in Tabman don't support Dynamic Type - so this is why you won't see the label font changing with the system setting.

However this is going to be resolved with #560 which adds support for Dynamic Type 😄

You can enable it on the buttons by doing the following:

bar.buttons.customize {
    $0.adjustsFontForContentSizeCategory = true
}

The buttons now default to using a font with a specified text style that will support Dynamic Type when adjustsFontForContentSizeCategory but you can of course set a custom font that supports this. It also requires iOS 11.

msaps commented 3 years ago

Now available in 2.11.0 🚀

mkoorn commented 3 years ago

Hi @msaps, thanks for the update. I'm now revisiting this since supporting dynamic type was postponed for me.

I still have an issue. The problem is that I am using a custom font added to the application.

The font is for example created by: UIFont(name: "fontName", size: 14) then the scaledFont is created with: UIFontMetrics(forTextStyle: textStyle).scaledFont(for: font)

The problem is I think in:

private func reloadTextLayerForCurrentFont() {
    if #available(iOS 11, *), adjustsFontForContentSizeCategory, let font = font, let textStyle = font.fontDescriptor.object(forKey: .textStyle) as? UIFont.TextStyle {
        let font = UIFontMetrics(forTextStyle: textStyle).scaledFont(for: font)
        textLayer.font = font
        textLayer.fontSize = font.pointSize
    } else {
        textLayer.font = font
        textLayer.fontSize = font?.pointSize ?? 17.0
    }
    invalidateIntrinsicContentSize()
    superview?.setNeedsLayout()
    superview?.layoutIfNeeded()
}

the font I provide does not have a textstyle in the fontDescriptor, but also, I don't think we can create a scaled font from a scaled font.

Any ideas how to support custom dynamic fonts?