AdjustsFontSizeToFitWidth 与 SizeToFit [英] AdjustsFontSizeToFitWidth vs. SizeToFit
问题描述
我使用 SizeToFit
因为我不必指定 Frame
属性来具有 UIButton
/<的自适应大小代码>UILabel.就我而言,它是工具栏上的一个按钮.现在我做了以下观察:
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:
如果我将 AdjustsFontSizeToFitWidth
与 SizeToFit
一起使用,则字体大小不再适用.所以我可以
If I use AdjustsFontSizeToFitWidth
together with SizeToFit
than the font size isn't adapted anymore. So I can
- 指定一个
Frame
并使用AdjustsFontSizeToFitWidth
- 使用
SizeToFit
但不再有可调整的字体大小
- Specify a
Frame
and useAdjustsFontSizeToFitWidth
- Use
SizeToFit
but don't have the adjustable font size anymore
你也有这个问题吗?你如何规避这个问题?如何让内在内容大小驱动帧大小?还是我必须设置 Frame
属性?Autolayout 的优点是不再定义边框大小......
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 ...
推荐答案
我想我在推理上犯了一个错误.SizeToFit
定义内容后的大小(内容已经有固定大小).AdjustsFontSizeToFitWidth
需要一个可以改变字体大小的框架.两者一起不起作用.
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.
这篇关于AdjustsFontSizeToFitWidth 与 SizeToFit的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!