I've gone through a load of posts on SO for this and nothing is working. Why does "Cheese!" not shrink at all? I checked the bounds of the label at runtime and they're fine. This is a plain (not attributed) UILabel.
为此,我已经在SO上发布了很多帖子,没有任何工作。为什么“奶酪!”根本不缩水?我在运行时检查了标签的边界,它们很好。这是一个简单的(未归因的)UILabel。
This code runs after viewDidAppear
.
此代码在viewDidAppear之后运行。
self.cameraCountdownLabel.numberOfLines = 1;
self.cameraCountdownLabel.font = [UIFont fontWithName:@"OpenSans-Bold" size:300.0];
self.cameraCountdownLabel.adjustsFontSizeToFitWidth = true;
self.cameraCountdownLabel.minimumScaleFactor = 0.1;
self.cameraCountdownLabel.lineBreakMode = NSLineBreakByTruncatingTail;
self.cameraCountdownLabel.text = LocalizedMajor(@"Cheese!",nil);
Why does "Cheese!" not shrink at all?
为什么“奶酪!”根本不缩水?
2 个解决方案
#1
1
Without seeing the constraints or frame layout code that set the size of your label, it's hard to say. But it is worth noting that changing the height of a label will not change the font size of the contents to fit. Only width is considered. So if your label gets compressed vertically and you are hoping that the font will shrink to keep the text visible without clipping, you will need to try a different approach like an aspect ratio constraint. Only shrinking the width of a label will trigger a reduction of font size in order to make the text fit horizontally in the space available.
没有看到设置标签大小的约束或框架布局代码,很难说。但值得注意的是,更改标签的高度不会改变要适合的内容的字体大小。只考虑宽度。因此,如果您的标签被垂直压缩并且您希望字体缩小以保持文本可见而不剪切,则需要尝试不同的方法,如宽高比约束。仅缩小标签的宽度将触发字体大小的减小,以使文本在可用空间中水平适合。
#2
0
Turns out the label's superview had a constraint for its width that was somehow only priority 749 (optional), and although checking the bounds after the text was set in the debugger, it was indeed (later!) growing its bounds. The fix was to change the superivew's width-constraint's priority to 1000.
事实证明,标签的superview对其宽度有一个约束,它只是优先级749(可选),虽然在调试器中设置文本之后检查边界,但确实(稍后!)增长了它的界限。修复是将superivew的width-constraint的优先级更改为1000。
For others, the way to debug this was to set a breakpoint after the text was set in the label, check the label's bounds with po labelname
, then to add the following code only for debugging to check the bounds again after some time:
对于其他人来说,调试它的方法是在标签中设置文本后设置断点,用po labelname检查标签的边界,然后添加以下代码仅用于调试以在一段时间后再次检查边界:
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
(breakpoint here)
#1
1
Without seeing the constraints or frame layout code that set the size of your label, it's hard to say. But it is worth noting that changing the height of a label will not change the font size of the contents to fit. Only width is considered. So if your label gets compressed vertically and you are hoping that the font will shrink to keep the text visible without clipping, you will need to try a different approach like an aspect ratio constraint. Only shrinking the width of a label will trigger a reduction of font size in order to make the text fit horizontally in the space available.
没有看到设置标签大小的约束或框架布局代码,很难说。但值得注意的是,更改标签的高度不会改变要适合的内容的字体大小。只考虑宽度。因此,如果您的标签被垂直压缩并且您希望字体缩小以保持文本可见而不剪切,则需要尝试不同的方法,如宽高比约束。仅缩小标签的宽度将触发字体大小的减小,以使文本在可用空间中水平适合。
#2
0
Turns out the label's superview had a constraint for its width that was somehow only priority 749 (optional), and although checking the bounds after the text was set in the debugger, it was indeed (later!) growing its bounds. The fix was to change the superivew's width-constraint's priority to 1000.
事实证明,标签的superview对其宽度有一个约束,它只是优先级749(可选),虽然在调试器中设置文本之后检查边界,但确实(稍后!)增长了它的界限。修复是将superivew的width-constraint的优先级更改为1000。
For others, the way to debug this was to set a breakpoint after the text was set in the label, check the label's bounds with po labelname
, then to add the following code only for debugging to check the bounds again after some time:
对于其他人来说,调试它的方法是在标签中设置文本后设置断点,用po labelname检查标签的边界,然后添加以下代码仅用于调试以在一段时间后再次检查边界:
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
(breakpoint here)