• <small id='kC9Im'></small><noframes id='kC9Im'>

      • <bdo id='kC9Im'></bdo><ul id='kC9Im'></ul>

        <tfoot id='kC9Im'></tfoot>

      1. <legend id='kC9Im'><style id='kC9Im'><dir id='kC9Im'><q id='kC9Im'></q></dir></style></legend>
        <i id='kC9Im'><tr id='kC9Im'><dt id='kC9Im'><q id='kC9Im'><span id='kC9Im'><b id='kC9Im'><form id='kC9Im'><ins id='kC9Im'></ins><ul id='kC9Im'></ul><sub id='kC9Im'></sub></form><legend id='kC9Im'></legend><bdo id='kC9Im'><pre id='kC9Im'><center id='kC9Im'></center></pre></bdo></b><th id='kC9Im'></th></span></q></dt></tr></i><div id='kC9Im'><tfoot id='kC9Im'></tfoot><dl id='kC9Im'><fieldset id='kC9Im'></fieldset></dl></div>

        如何在自动布局iOS中动态更改字体大小?

        时间:2023-09-11

          <i id='r7T3J'><tr id='r7T3J'><dt id='r7T3J'><q id='r7T3J'><span id='r7T3J'><b id='r7T3J'><form id='r7T3J'><ins id='r7T3J'></ins><ul id='r7T3J'></ul><sub id='r7T3J'></sub></form><legend id='r7T3J'></legend><bdo id='r7T3J'><pre id='r7T3J'><center id='r7T3J'></center></pre></bdo></b><th id='r7T3J'></th></span></q></dt></tr></i><div id='r7T3J'><tfoot id='r7T3J'></tfoot><dl id='r7T3J'><fieldset id='r7T3J'></fieldset></dl></div>
            <tbody id='r7T3J'></tbody>

          <tfoot id='r7T3J'></tfoot>

            <small id='r7T3J'></small><noframes id='r7T3J'>

            1. <legend id='r7T3J'><style id='r7T3J'><dir id='r7T3J'><q id='r7T3J'></q></dir></style></legend>
              • <bdo id='r7T3J'></bdo><ul id='r7T3J'></ul>
                • 本文介绍了如何在自动布局iOS中动态更改字体大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想将我的文本放在 UILabel 中,但对于不同的 iPhone,UILabel 的大小正在改变,因为我使用的是自动布局,但我不能修复字体大小,所以我的文字被剪掉了.

                  有什么方法可以设置任何约束,使文本动态适合 UILabel?

                  在检查器中,您必须在 Autoshrink 前面选择最小字体比例或最小字体大小.这使内容能够更改字体大小以适合标签.

                  在这里,我将最小字体比例设置为 0,5,因此最小大小是当前大小的一半 (31.0).文本将尝试适应,直到达到最小比例/大小.

                  (一般不要使用Tighten letter spacing"来达到这个目的.Tighten letter spacing使用相同的字体大小,减少字母之间的间距.它可以使标签在截断前紧缩5%,但在最小时无效字体比例/大小已启用.)

                  <小时>

                  您可能希望使用 iPad Pro 等宽屏设备以及 iPhone 4S 等小屏幕设备进行测试.作为一个好的做法,您应该使用不同的用户系统字体大小进行测试,您可以在 Settings>General>Accessibility>Larger 中设置它们文本.

                  Autoshrink 不会调整大于标签上设置的字体大小,这意味着如果您将标签设置为与屏幕相同的宽度但将字体大小保留为 14,它会尝试增加字体大小直到达到该大小.

                  要使其真正起作用,请选择字体大小.

                  您仍然可以将 autoshrink 与大小类结合使用,以根据设备/方向更改最大字体大小.

                  <小时>

                  如果您想将 autoshrinkUIButton 一起使用,您仍然可以使用两行代码来设置此行为.

                  myButton.titleLabel.minimumScaleFactor = 0.5;myButton.titleLabel.adjustsFontSizeToFitWidth = YES;

                  I want to fit my text in a UILabel, but for different iPhone the size of the UILabel is changing, as I'm using auto layout, but I cannot fix the font size, so my text is cutting out.

                  Is there any way I can set any constraint so that the text fits in the UILabel dynamically?

                  See here the text got cut, because of different screen resolution

                  解决方案

                  You should use autoshrink.

                  Since all iPhones have the same Compact width size class when in portrait mode, you can't rely on this to handle your label size.


                  Previews are for iPhone5, iPhone6 and iPhone 6+

                  In the inspector, you must select minimum font scale or minimum font size in front of Autoshrink. This enables the content to change the size of the font to fit in the label.

                  Here, I set minimum font scale to 0,5 so the minimum size is half of the current size (31.0). The text will try to fit until it reaches the minimum scale/size.

                  (Generally do not use "Tighten letter spacing" for this purpose. Tighten letter spacing uses the same font size and reduces spacing between letters. It can make the label up to 5% tighter before truncating, but it's not effective when minimum font scale/size is enabled.)


                  You may want to test with a wide screen device such as the iPad Pro, and also on a smaller screen such as the iPhone 4S. As a good practice you should test with different user system font sizes, you can set them in Settings>General>Accessibility>Larger Text.

                  Autoshrink will not adjust the font size bigger than the one set on the label, that means if you make the label the same width as the screen but leave the font size to 14, it will try to increase the font size until it reaches that size.

                  To make it actually work, select a big font size.

                  You can still combine autoshrink with size classes to change the maximum font size depending on the device/the orientation.


                  In case you want to use autoshrink with UIButtons, you can still set this behavior with two lines of code.

                  myButton.titleLabel.minimumScaleFactor = 0.5;
                  myButton.titleLabel.adjustsFontSizeToFitWidth = YES;
                  

                  这篇关于如何在自动布局iOS中动态更改字体大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何在 iOS 自动布局中为按钮添加等间距和等宽 下一篇:AutoLayout 链接两个 UILabel 以具有相同的字体大小

                  相关文章

                      <tfoot id='Zb9BQ'></tfoot>

                    1. <legend id='Zb9BQ'><style id='Zb9BQ'><dir id='Zb9BQ'><q id='Zb9BQ'></q></dir></style></legend>

                      <small id='Zb9BQ'></small><noframes id='Zb9BQ'>

                      <i id='Zb9BQ'><tr id='Zb9BQ'><dt id='Zb9BQ'><q id='Zb9BQ'><span id='Zb9BQ'><b id='Zb9BQ'><form id='Zb9BQ'><ins id='Zb9BQ'></ins><ul id='Zb9BQ'></ul><sub id='Zb9BQ'></sub></form><legend id='Zb9BQ'></legend><bdo id='Zb9BQ'><pre id='Zb9BQ'><center id='Zb9BQ'></center></pre></bdo></b><th id='Zb9BQ'></th></span></q></dt></tr></i><div id='Zb9BQ'><tfoot id='Zb9BQ'></tfoot><dl id='Zb9BQ'><fieldset id='Zb9BQ'></fieldset></dl></div>
                        <bdo id='Zb9BQ'></bdo><ul id='Zb9BQ'></ul>