0

I would like to have an adaptative text in my UITabBarItem that minimize the font size if it get too large.

For example:

image1
image2

Here is my code:

UITabBarItem.appearance().setTitleTextAttributes([NSAttributedString.Key.font: UIFont(name: "Read-Regular", size: 10)!], for: .normal)
                    UITabBarItem.appearance().setTitleTextAttributes([NSAttributedString.Key.font: UIFont(name: "Read-Regular", size: 10)!], for: .selected)
                    UITabBarItem.appearance().setTitleTextAttributes([NSAttributedString.Key.foregroundColor: UIColor.black], for: .normal)
                    UITabBarItem.appearance().setTitleTextAttributes([NSAttributedString.Key.foregroundColor: UIColor.white], for: .selected)

Is there any option equivalent to the label:

valueLabel.adjustsFontSizeToFitWidth = true
valueLabel.minimumFontSize = 0.5

Thanks in advance.

ΩlostA
  • 2,501
  • 5
  • 27
  • 63
  • There is no label so it is unclear what the question is. You are setting the font size "too large" and then complaining that it is too large...? If you don't like the font size, don't do that. – matt Nov 05 '20 at 15:45
  • 1
    Then do that. It isn't going to happen magically by itself. Measure the size of the proposed text / font and if it's too big, make the font size small enough that it _isn't_ too big. – matt Nov 05 '20 at 16:00
  • @matt yep, I thought that there was something existing. I will do that. Thank you. – ΩlostA Nov 05 '20 at 16:01
  • Why don't you increase the red background instead? :) – Ivan Georgiev Nov 05 '20 at 20:17

0 Answers0