Subclassing UIButton doesn't change font size

Hi, here is a class for a UIKIT button. Some of those settings work, usch as cornerRadius: it does affect the button display, but some doesn't.

For example, the size from

   self.titleLabel?.font = UIFont(name: "Avenir Next Condensed Regular", size: 3)

has no effect at all on the text of the font inside the buttons.

Why is that? And how can I effectively alter the size of text from this subclass?

class VotingButtonStyle: UIButton {

   
  override func draw(_ rect: CGRect) {
    super.draw(rect)
    self.clipsToBounds = true
    self.titleLabel?.font = UIFont(name: "Avenir Next Condensed Regular", size: 3)
    self.setTitleColor(.black, for: .normal)
    self.titleLabel?.numberOfLines = 3
    self.layer.cornerRadius = 8
  }

   
}
Answered by Claude31 in 676897022

No, the problem is that Regular does not exist for this font.

It works as well with It does not work with "Avenir Next Condensed".

Probably your font does not exist in your system.

I tested with

          self.titleLabel?.font = UIFont(name: "Helvetica", size: 3)

And it works.

It works as well with It does not work with "Avenir Next Condensed".

It does not work with "Avenir Next Condensed Regular".

Thank you for testing.

You are right, it has to do with font as with Helvetica it works. This is in my case in simulator iPhone 8, iOS 13.2.2

Maybe It's not the proper font label. As i'm sure this device/os has this font. I will investigate spelling.

Accepted Answer

No, the problem is that Regular does not exist for this font.

It works as well with It does not work with "Avenir Next Condensed".

Indeed, definitely a bad font name. Thank you, you saved me a lot of time.

Subclassing UIButton doesn't change font size
 
 
Q