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

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

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

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

      以编程方式更改标题在 IB 中设置为属性的 UIButton 的标题

      Programmatically change title of UIButton whose title was set in IB as attributed(以编程方式更改标题在 IB 中设置为属性的 UIButton 的标题)

          • <bdo id='aqgoe'></bdo><ul id='aqgoe'></ul>
              • <tfoot id='aqgoe'></tfoot>
              • <small id='aqgoe'></small><noframes id='aqgoe'>

                  <tbody id='aqgoe'></tbody>

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

                <legend id='aqgoe'><style id='aqgoe'><dir id='aqgoe'><q id='aqgoe'></q></dir></style></legend>
                本文介绍了以编程方式更改标题在 IB 中设置为属性的 UIButton 的标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                UIButton在使用前我已经改了标题:

                I have changed titles of UIButtons before using:

                - (void)setTitle:(NSString *)title forState:(UIControlState)state
                

                但是 我遇到了一种情况,其中 UIButton 我正在使用的有一个多行标题,并且如果在 IB 中从普通"更改为属性",则只会将文本正确居中.以这种方式更改标题时,通常的 setTitle: forState: 方法不再更新按钮.

                But I've run into a situation where the UIButton I'm using has a mult-line title and will only center the text properly if changed from "plain" to "attributed" in IB. When the title is changed in this way, the usual setTitle: forState: method no longer updates the button.

                如何更改 UIButton归属标题?

                为了澄清,所以你不要以为我只是犯了一个愚蠢的错误,我使用调试器来查看 UIButton 的属性并记录

                To clarify, so you don't assume I'm just making a stupid mistake, I've used the debugger to peek at the properties of the UIButton and logging the output of

                - (NSString *)titleForState:(UIControlState)state
                

                使用后

                - (void)setTitle:(NSString *)title forState:(UIControlState)state
                

                设置它返回刚刚设置的值.问题是,只要在 IB 中将标题设置为 attributed,它就不会改变按钮的外观.只需将其更改为 plain,我的代码就可以正常工作.但这不是上面链接中描述的解决方案.

                to set it returns the value just set. Problem is it doesn't change the appearance of the button as long as the title is set to attributed in IB. My code works fine by simply changing this to plain. But this is not a solution as described in the link above.

                推荐答案

                属性标题通过

                - (NSAttributedString *)attributedTitleForState:(UIControlState)state
                

                并通过设置

                - (void)setAttributedTitle:(NSAttributedString *)title forState:(UIControlState)state
                

                格式化 NSAttributedString 对象有点复杂,但将其设置为 nil 会清除标题,而这正是我所需要的.

                Formatting the NSAttributedString object is a bit complicated, but setting it to nil will clear the title and that's what I needed.

                这篇关于以编程方式更改标题在 IB 中设置为属性的 UIButton 的标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                UIButton title text color(UIButton 标题文本颜色)
                Stretch background image for UIButton(为 UIButton 拉伸背景图像)
                Using Tint color on UIImageView(在 UIImageView 上使用 Tint 颜色)
                How can I change UIButton title color?(如何更改 UIButton 标题颜色?)
                iPhone UIButton - image position(iPhone UIButton - 图像位置)
                UIButton remove all target-actions(UIButton 删除所有目标动作)

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

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

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

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