2

Trying to set UIButton's font for all buttons using appearance in iOS 8. After Googling, it appears that Apple has changed the way you do this from OS to OS. In iOS 7, this should have worked:

    UIButton.appearance().titleLabel?.font = UIFont.inviteButtonTitleFont()

But it doesn't seem to work anymore. Anyone know how you do it now?

RyJ
  • 3,995
  • 6
  • 34
  • 54

3 Answers3

5

Swift 3:

let fontRegular = UIFont(name: "MyCustomRegularFont", size: 17.0)
UILabel.appearance(whenContainedInInstancesOf: [UIButton.self]).font = fontRegular
UIButton.appearance().tintColor = UIColor.red
Peter Kreinz
  • 7,979
  • 1
  • 64
  • 49
0

The proxy for font was removed from UILabel.appearance(), so that's the reason why this not works.

Jan Cássio
  • 2,076
  • 29
  • 41
0

Use the appearance when contained in method on UILabel

UILabel.appearanceWhenContainedInInstancesOfClasses([UIButton.self]).font = UIFont.inviteButtonTitleFont()

This should work in iOS9, see this answer appearanceWhenContainedIn in Swift for iOS8 and 7 workarounds.

(Disclaimer, I have not compiled the code snippet so beware of typos).

Community
  • 1
  • 1
Lev Landau
  • 788
  • 3
  • 16