2

I use an array of 4 buttons and i want to resize the height of them depending on title size. Or resize characters of the title. What is the best and easiest? My buttons are btn1 btn2 btn3 btn4

for i in 0..<buttons.count{
            buttons[i].setTitle(Questions.[QNumber].Answers[i], for: UIControlState.normal)
        }
Alex Andreadis
  • 347
  • 1
  • 4
  • 17

1 Answers1

2

Ok, I have a few solutions for you. Your question asks to resize the height of the button OR the characters of the titleLabel.

  1. It's easier to adjust the size of the characters in the label. Here's the solution for that (replace btn with your buttons):

    btn.titleLabel?.minimumScaleFactor = 0.5
    btn.titleLabel?.numberOfLines = 0
    btn.titleLabel?.adjustsFontSizeToFitWidth = true
    
  2. Resizing the height of the buttons is a bit trickier. I've found a couple links to other answers that may work for you if you prefer this:

Thomas Wang
  • 2,233
  • 2
  • 14
  • 24