YMatterType icon indicating copy to clipboard operation
YMatterType copied to clipboard

TypographyButton has wrong height when contentEdgeInsets = .zero

Open mpospese opened this issue 2 years ago • 0 comments

The height of the typography button (ignoring images) for a single line text label should be:

typography.lineHeight + contentEdgeInsets.top + contentEdgeInsets.bottom

But when contentEdgeInsets == .zero (which is the default) then the height = typography.lineHeight + 12. It's as if the system then adds in content insets of {6, 0, 6, 0} (unsure of the leading/trailing values but they don't matter to this bug). If you set the insets to have one value of 0.0000001, even if it's to leading/trailing and top + bottom are both 0, then the button will have the correct height.

This seems to be some sort of bug or behavior in UIButton and it happens on iOS 14+ (all versions we support).

This bug means that by default TypographyButton has the wrong height (12 pts too tall), which is not good. We might have to resort to a nasty workaround like setting the insets to {0, 0.000001, 0, 0} and maybe also overriding contentEdgeInsets.didSet to intercept .zero and replace it with this alternate "almost zero" version to keep the bug from happening.

mpospese avatar Mar 24 '23 06:03 mpospese