我有一个UILabel(以黄色突出显示),它符合以下条件。
虽然这看起来像一个重复的问题但我认为不是。我遇到的问题是,当文本大小缩小到20个点后超过可用的3行长度时,UILabel的边界框大小不正确(即注意文本上下的无关间距)。
最终结果应该是没有任何间距的UILabel。是否有解决方案,同时保持行数为3?
答案 0 :(得分:1)
That looks like a bug. If you increase your base font size, you will see the space increase. Also, if you inspect the layout at runtime, you will see the content size to be calculated as too big.
My guess is, UILabel takes your original font size (40) to calculate the content size for 3 lines of text and does not take into account that the font size has already been decreased before truncation.
I fiddled with content hugging/compression priorities but could not make it work either.
The only workaround I found was to manually set the font size down to 20. That will get you the frame you want.