Search code examples
iosuiviewsizetofit

AdjustsFontSizeToFitWidth vs. SizeToFit


I'm using SizeToFit because I don't have to specify the Frame property to have an adaptive size of the UIButton/UILabel. In my case it's a button on a toolbar. Now I made the following observation:

If I use AdjustsFontSizeToFitWidth together with SizeToFit than the font size isn't adapted anymore. So I can

  1. Specify a Frame and use AdjustsFontSizeToFitWidth
  2. Use SizeToFit but don't have the adjustable font size anymore

Do you also have this problem? How do you circumvent this problem? How to let the intrinsic content size drive the frame size? Or do I have to set the Frame property? The advantage of Autolayout was to not define a frime size any more ...


Solution

  • I think I made an error in reasoning. SizeToFit defines the size after the content (content has already a fixed size). AdjustsFontSizeToFitWidth needs a frame in which it can change the font size. Both together doesn't work.