CosmicMind / Material

A UI/UX framework for creating beautiful applications.
http://cosmicmind.com
MIT License
11.98k stars 1.26k forks source link

Button's title font set in Storyboard/IB will be discarded #1230

Closed mohpor closed 5 years ago

mohpor commented 5 years ago

Hi,

Material 3.x (and Theming to be more specific), discards font's set on Buttons in IB.

titleLabel?.font = Theme.font.regular(with: fontSize)

this line will override the button's font, regardless of you opting out of theming.

I guess it should check to see if Theming (globally) is enabled before changing values.

e.g.:


if Theme.isEnabled {
   titleLabel?.font = Theme.font.regular(with: fontSize)
}

For now, the workaround is to set button's font in code.

OrkhanAlikhanov commented 5 years ago

Hmm, titleLabel?.font = has always been around setting font to roboto, we've just updated it to use Theme.font instead of RobotoFont directly.

If we add Theme.isEnabled check it then next time a dev updates Material will end up seeing different font if it hasn't been changed previously in code.

I think we may check if font is set by user by comparing current one with default one:

let defaultButtonFont = UIFont.systemFont(ofSize: UIFont.buttonFontSize)
if titleLabel?.font == defaultButtonFont {
    titleLabel?.font = Theme.font.regular(with: fontSize)
}

@mohpor Can you please try above code and see if it works for you?

mohpor commented 5 years ago

Then it must be something else that is triggering the font update.

I have a rather large project that has many many Button instants, after updating to Material 3.x, all of those which rely on IB for font description now have lost the font.

I already have a workaround, but due to the vast amount of revision and coding effort, I had to revert back to 2.16.4

If we add Theme.isEnabled check it then next time a dev updates Material will end up seeing different font if it hasn't been changed previously in code.

this is what has happened to me unfortunately.

OrkhanAlikhanov commented 5 years ago

Ahh, I am mistaken. The line was added by me in https://github.com/CosmicMind/Material/commit/cf36b57ff18ec1607715456e0354e109ffebc9c1 It was not there before.

OrkhanAlikhanov commented 5 years ago

The reason why I added it, I believe, was that @danieldahan had been changing font to RobotoFont after creating a button throughout the sample projects. I just wanted to eliminate it by setting it in the library itself which unfortunately seems to a breaking change for storyboard users. @danieldahan I think we should remove the line back. What do you think?

OrkhanAlikhanov commented 5 years ago

btw, thank you for reporting this @mohpor 💪

OrkhanAlikhanov commented 5 years ago

Hey @mohpor! You can try #1231 to see if it fixes your issue.

daniel-jonathan commented 5 years ago

Hi @mohpor please find the latest release with the above fixes here https://github.com/CosmicMind/Material/releases/tag/3.1.1.