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

      <bdo id='X8eg8'></bdo><ul id='X8eg8'></ul>
  • <small id='X8eg8'></small><noframes id='X8eg8'>

    <legend id='X8eg8'><style id='X8eg8'><dir id='X8eg8'><q id='X8eg8'></q></dir></style></legend>

        如何以编程方式将 UIButton 调整为文本大小并保持漂亮的填充?

        时间:2023-07-08
              <bdo id='s88Rn'></bdo><ul id='s88Rn'></ul>
              <tfoot id='s88Rn'></tfoot>
                <tbody id='s88Rn'></tbody>
              <legend id='s88Rn'><style id='s88Rn'><dir id='s88Rn'><q id='s88Rn'></q></dir></style></legend>
              <i id='s88Rn'><tr id='s88Rn'><dt id='s88Rn'><q id='s88Rn'><span id='s88Rn'><b id='s88Rn'><form id='s88Rn'><ins id='s88Rn'></ins><ul id='s88Rn'></ul><sub id='s88Rn'></sub></form><legend id='s88Rn'></legend><bdo id='s88Rn'><pre id='s88Rn'><center id='s88Rn'></center></pre></bdo></b><th id='s88Rn'></th></span></q></dt></tr></i><div id='s88Rn'><tfoot id='s88Rn'></tfoot><dl id='s88Rn'><fieldset id='s88Rn'></fieldset></dl></div>

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

                  本文介绍了如何以编程方式将 UIButton 调整为文本大小并保持漂亮的填充?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个动态创建的按钮,需要调整大小.它有足够的空间来增长,但调用 sizeToFit 接缝什么也不做,或者至少没有足够放大按钮.

                  I have a button that is created dynamically and needs to be resized. It has plenty of space where to grow but calling sizeToFit seams to do nothing or at least not enlarging the button enough.

                  如何才能获得想要的效果?

                  How can I obtain the desired effect?

                  推荐答案

                  查看 NSString 方法 -sizeWithFont:.它返回一个 CGSize ,它将通知您按钮中的文本需要多大的大小.然后,您可以根据此大小调整按钮的框架,将您想要的任何填充添加到按钮框架的宽度和高度.像这样的:

                  Check out the NSString method -sizeWithFont:. It returns a CGSize that will inform you as to how much size your text will need in the button. Then you can adjust the button's frame based on this size, adding whatever padding you desire to the width and height of the button's frame. Something like this:

                  NSString *msg = @"The button label";
                  UIFont *font = [UIFont systemFontOfSize:17];
                  CGSize msgSize = [msg sizeWithFont:font];
                  CGRect frame = button.frame;
                  frame.size.width = msg.size.width+10;
                  frame.size.height = msg.size.height+10;
                  button.frame = frame;
                  

                  (从内存中写入;未编译.:-)

                  (written from memory; not compiled. :-)

                  当然,你还要设置按钮的标题和字体……

                  Of course, you have to set the button title and font as well...

                  这篇关于如何以编程方式将 UIButton 调整为文本大小并保持漂亮的填充?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:是否有可能成功地为移动的 UIButton 设置动画? 下一篇:如果它们都具有相同的 IBAction,如何定义按下哪个按钮?

                  相关文章

                  <legend id='7QIkp'><style id='7QIkp'><dir id='7QIkp'><q id='7QIkp'></q></dir></style></legend>

                  1. <small id='7QIkp'></small><noframes id='7QIkp'>

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