简体   繁体   English

UILabel AutoResize剪切文本的顶部

[英]UILabel AutoResize cuts off the top part of the text

I have a UILabel which autoresizes along with its parent view. 我有一个UILabel及其父视图会自动调整大小。 The label has AdjustsFontSizeToWidth turned on and has a minimum text size of 0 - so basically it tries to fit all the text into whatever size the UILabel is. 该标签已启用AdjustsFontSizeToWidth且最小文本大小为0-因此,基本上,它会尝试将所有文​​本调整为UILabel的任何大小。

The problem I am having is that vertically the text gets cut off. 我遇到的问题是,垂直方向上的文本被截断了。 So yes, the label is adjusting its font size to the width of the label but the text is too tall for the label and thus some of the text is getting cut off. 因此,是的,标签正在将其字体大小调整为标签的宽度,但是文本对于标签而言太大,因此某些文本被截断。

Is there anyway to work around this so that all of the text, the full height and full width are shown? 是否有任何解决方法,以便显示所有文本,全高和全宽?

I attach an image to show what I mean. 我附上一张图片以显示我的意思。 The red box is the parent view, the purple box is the UILabel. 红色框是父视图,紫色框是UILabel。

Thanks for your help. 谢谢你的帮助。

文字被截断

What you are adjusting automatically is the Width and not the Height. 您正在自动调整的是宽度而不是高度。 The Height is something you'll have to adjust manually based on the maximum font size you will use. 高度是您必须根据将使用的最大字体大小手动调整的一项。 If the maximum (assigned initial) font size fits in height, so will the smaller one's do, after they are automatically adjusted 如果最大(指定的初始)字体大小适合高度,则较小的字体在自动调整后也会这样做

I suspect that Lefteris is right, that minimum text size focuses on font size for the width of the control. 我怀疑Lefteris是正确的,最小文本大小集中在控件宽度的字体大小上。 Note, though, if you want it to resize the font to fit, you want a non-zero minFontSize. 但是请注意,如果希望它调整字体大小以适合字体,则需要一个非零的minFontSize。 See minimizeFontSize notes. 请参阅minimumFontSize注释。 Also check out the various NSString UIKit Additions that can be used to get the size of the control necessary to fit your text, and programmatically adjust the size (ie the frame) your UILabel accordingly. 还要检查各种NSString UIKit附加项 ,这些附加项可用于获取适合您的文本的控件的大小,并以编程方式相应地调整UILabel的大小(即框架)。

In my case there was a bogus vertical centering of a view under the labels being clipped and squashed. 以我为例,在被裁剪和压扁的标签下,视图的假垂直居中位置。 That somehow took priority over compression resistance priority of 1000 for the labels. 以某种方式优先于标签的抗压缩优先级1000。 No warning on console about conflict though. 控制台上没有关于冲突的警告。 But the view debugger was of some help. 但是视图调试器有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM