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

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

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

      1. <legend id='yxSfe'><style id='yxSfe'><dir id='yxSfe'><q id='yxSfe'></q></dir></style></legend>
      2. 突出显示时如何更改 UIButton 的背景颜色?

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

            • <legend id='KVUOQ'><style id='KVUOQ'><dir id='KVUOQ'><q id='KVUOQ'></q></dir></style></legend>
                  <tbody id='KVUOQ'></tbody>

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

                <tfoot id='KVUOQ'></tfoot>
                  <bdo id='KVUOQ'></bdo><ul id='KVUOQ'></ul>
                • 本文介绍了突出显示时如何更改 UIButton 的背景颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  在我的应用程序中的某个时刻,我有一个突出显示的 UIButton(例如,当用户将手指放在按钮上时)并且我需要在按钮突出显示时更改背景颜色(所以当用户的手指仍在按钮上).

                  At some point in my app I have a highlighted UIButton (for example when a user has his finger on the button) and I need to change the background color while the button is highlighted (so while the finger of the user is still on the button).

                  我尝试了以下方法:

                  _button.backgroundColor = [UIColor redColor];
                  

                  但它不起作用.颜色保持不变.当按钮未突出显示并且工作正常时,我尝试了相同的代码.我也试过在改变颜色后调用-setNeedsDisplay,没有任何效果.

                  But it is not working. The color remains the same. I tried the same piece of code when the button is not highlighted and it works fine. I also tried calling -setNeedsDisplay after changing the color, it didn't have any effect.

                  如何强制按钮改变背景颜色?

                  How to force the button to change the background color?

                  推荐答案

                  你可以重写UIButtonsetHighlighted方法.

                  Objective-C

                  - (void)setHighlighted:(BOOL)highlighted {
                      [super setHighlighted:highlighted];
                  
                      if (highlighted) {
                          self.backgroundColor = UIColorFromRGB(0x387038);
                      } else {
                          self.backgroundColor = UIColorFromRGB(0x5bb75b);
                      }
                  }
                  

                  Swift 3.0 和 Swift 4.1

                  override open var isHighlighted: Bool {
                      didSet {
                          backgroundColor = isHighlighted ? UIColor.black : UIColor.white
                      }
                  }
                  

                  这篇关于突出显示时如何更改 UIButton 的背景颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:获取 UITableViewCell 内的按钮单击 下一篇:子类 UIButton 添加属性

                  相关文章

                • <small id='4SO3h'></small><noframes id='4SO3h'>

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

                    • <bdo id='4SO3h'></bdo><ul id='4SO3h'></ul>
                    <legend id='4SO3h'><style id='4SO3h'><dir id='4SO3h'><q id='4SO3h'></q></dir></style></legend>

                      <tfoot id='4SO3h'></tfoot>