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

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

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

        如何在 UIButton 子类中覆盖 -drawrect?

        时间:2023-07-09
        • <tfoot id='DsLuL'></tfoot>
        • <small id='DsLuL'></small><noframes id='DsLuL'>

          • <legend id='DsLuL'><style id='DsLuL'><dir id='DsLuL'><q id='DsLuL'></q></dir></style></legend>

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

                  <tbody id='DsLuL'></tbody>
                • <bdo id='DsLuL'></bdo><ul id='DsLuL'></ul>
                • 本文介绍了如何在 UIButton 子类中覆盖 -drawrect?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  HI. I need to write some text over a custom button. So I subclassed UIButton. In -drawrect, I write the text I need. The problem is that the text ends up under the button. After I write my text, UIButton's drawrect goes ahead and draws on top of me.

                  I am not even calling [super drawrect: rect] even though I was anticipating calling it before I did my drawing. It seems that UIButton's drawrect will get called regardless.

                  Any ideas? Thanks.

                  解决方案

                  As other people have said, you don't need to subclass UIButton - infact it's best not to as UIButton is pretty complex (as you found). You have three options:

                  • Leave the button's title blank and add a new text field to the button at the position you want.
                  • if you are using 3.0 access the button's label property. Although the label itself is read only its properties (including frame) are not.
                  • Sub-class UIControl. UIControl is a UIView so you can add other views - text and images and it is UIView that implements the action message behaviour (addTarget:action:forControlEvents:). UIButton implements statefulness on top of this.

                  If you don't need things like UIButton's setTitle:forState: and associated functionality but you are using a lot of these controls I would use the third option. Otherwise use the first (or second if you are on 3.0).

                  这篇关于如何在 UIButton 子类中覆盖 -drawrect?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何禁用 UIButton? 下一篇:为什么我的 UIButton.tintColor 不起作用?

                  相关文章

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

                • <tfoot id='RA4od'></tfoot>

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

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

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