1. <small id='gFouU'></small><noframes id='gFouU'>

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

        • <bdo id='gFouU'></bdo><ul id='gFouU'></ul>
        <tfoot id='gFouU'></tfoot>
      2. <i id='gFouU'><tr id='gFouU'><dt id='gFouU'><q id='gFouU'><span id='gFouU'><b id='gFouU'><form id='gFouU'><ins id='gFouU'></ins><ul id='gFouU'></ul><sub id='gFouU'></sub></form><legend id='gFouU'></legend><bdo id='gFouU'><pre id='gFouU'><center id='gFouU'></center></pre></bdo></b><th id='gFouU'></th></span></q></dt></tr></i><div id='gFouU'><tfoot id='gFouU'></tfoot><dl id='gFouU'><fieldset id='gFouU'></fieldset></dl></div>
      3. 如何让文本适合 UIButton?

        时间:2023-07-07

      4. <tfoot id='ZPNph'></tfoot>

            <tbody id='ZPNph'></tbody>

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

            <bdo id='ZPNph'></bdo><ul id='ZPNph'></ul>

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

                1. 本文介绍了如何让文本适合 UIButton?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  按钮大小足够了,但是当我更改标题时,标题文本无法适应按钮宽度.任何SDK功能都可以解决这个问题,还是我需要手动编码才能解决?

                  Button size is enough, however when I change title, the title text cannot fit the button width. Any SDK function can solve this problem, or I need to manually code to solve it?

                  请参考以下图片.

                  在 nib 文件中设计.

                  design in the nib file.

                  模拟器中的初始显示

                  当我更改标题文本时

                  1. _button.titleLabel.adjustsFontSizeToFitWidth = YES;
                    这种方式会改变我的字体大小.我不能接受这种方式.

                  1. _button.titleLabel.adjustsFontSizeToFitWidth = YES;
                    the way will change my font size. I cannot accept the way.

                  [_button setTitleEdgeInsets:UIEdgeInsetsMake(10.0, 10.0, 0.0,0.0)];
                  方式只改变标签的位置,不改变标签的大小.

                  [_button setTitleEdgeInsets:UIEdgeInsetsMake(10.0, 10.0, 0.0,0.0)];
                  the way change label's position only, not label size.

                  [_button.titleLabel sizeToFit];
                  结果与图片(3)相同.

                  [_button.titleLabel sizeToFit];
                  result is same with picture(3).

                  [_button sizeToFit];
                  标题移到左上角,标题还是一样的结果.

                  [_button sizeToFit];
                  title moved to upper left corner, and the title still the same result.

                  一头雾水,我的按钮大小够大,标题怎么这么小?

                  Just confused, my button size is big enough, why title size is so small?

                  推荐答案

                  使用这个.

                  目标-c

                  button.titleLabel.numberOfLines = 1;
                  button.titleLabel.adjustsFontSizeToFitWidth = YES;
                  button.titleLabel.lineBreakMode = NSLineBreakByClipping; 
                  

                  斯威夫特 2.0

                  button.titleLabel?.numberOfLines = 0
                  button.titleLabel?.adjustsFontSizeToFitWidth = true
                  button.titleLabel?.lineBreakMode = NSLineBreakMode.ByWordWrapping
                  

                  注意:Swift 代码礼貌:@Rachel Harvey

                  NOTE: Swift code courtesy: @Rachel Harvey

                  斯威夫特 5.0

                  button.titleLabel?.numberOfLines = 0
                  button.titleLabel?.adjustsFontSizeToFitWidth = true
                  button.titleLabel?.lineBreakMode = .byWordWrapping
                  

                  这篇关于如何让文本适合 UIButton?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:在突出显示时更改 UIButton 边框颜色 下一篇:如果按下子视图的按钮,如何取消 UIGestureRecognizer

                  相关文章

                2. <legend id='BPhcZ'><style id='BPhcZ'><dir id='BPhcZ'><q id='BPhcZ'></q></dir></style></legend>

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

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

                      <tfoot id='BPhcZ'></tfoot>
                        <bdo id='BPhcZ'></bdo><ul id='BPhcZ'></ul>