Maximilian Körner
Maximilian Körner

Reputation: 894

appearance proxy not working as intended for UIButton font

im currently styling my app via the appearance proxy and i ran into this problem: when i set properties on the UIButton appearance my font is ignored:

[buttonAppearance setTitleColor:darkColor forState:UIControlStateNormal];
[buttonAppearance.titleLabel setFont:[UIFont fontWithName:@"Helvetica Neue" size:10.0]];

the first line is applied properly (darkColor is some UIColor), but my font change is ignored completely. When i copy the line into my ViewController and apply it to a concrete button it works fine.

Am i missing something?

any help appreciated! ty

Upvotes: 0

Views: 3113

Answers (2)

mt81
mt81

Reputation: 3318

I have found this class TWTButton.h, who resolved my problems adding a new appearance selector [setTitleFont:] to the UIButton class.

buttonAppearance = [TWTButton appearance];
[buttonAppearance setTitleFont:[UIFont systemFontOfSize:10.0f]];

You may read more about this here : http://toastmo.com/blog/2013/01/17/uiappearance/

Upvotes: 1

danypata
danypata

Reputation: 10175

The font name is wrong, it should be HelveticaNeue, without the space between.

In the future if you want to see other iOS font names you should check this website piece of code

EDIT

After a closer look I realized that you are trying to set the appearance of the button's title which is a UILabel, sadly UILabel doesn't have the font property in the UIAppearance proxy and that's why the font doesn't work.

Upvotes: 3

Related Questions