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

      <legend id='5eK1I'><style id='5eK1I'><dir id='5eK1I'><q id='5eK1I'></q></dir></style></legend>
        <bdo id='5eK1I'></bdo><ul id='5eK1I'></ul>
        <tfoot id='5eK1I'></tfoot>

        <small id='5eK1I'></small><noframes id='5eK1I'>

      1. 按下时 UIButton 不突出显示

        时间:2023-07-07
        • <bdo id='G1hDC'></bdo><ul id='G1hDC'></ul>
            <tbody id='G1hDC'></tbody>
        • <legend id='G1hDC'><style id='G1hDC'><dir id='G1hDC'><q id='G1hDC'></q></dir></style></legend>

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

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

                  <tfoot id='G1hDC'></tfoot>

                  本文介绍了按下时 UIButton 不突出显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我的 UIButton 实例在按下时未突出显示.我很确定我的代码是正确的.这只发生在我正在使用的这个特定类中.我猜是因为该函数已被我遵守的协议覆盖.

                  我想让 UIButton 突出显示默认方式,但我必须手动完成.如何在按下时强制突出显示按钮,它的默认设置是什么(在颜色方面),以便与所有其他按钮保持一致?

                  这是我当前的代码:

                   让 backButton = UIButton()backButton.setTitle("返回", for: .normal)backButton.setTitleColor(UIColor.black, for: .normal)backButton.adjustsImageWhenHighlighted = trueRevealBar.addSubview(backButton)backButton.snp.makeConstraints { (make) ->无效make.center.equalTo(RevealBar)make.width.equalTo(RevealBar)make.height.equalTo(RevealBar)}backButton.addTarget(self, action: #selector(self.goBack), for: .touchUpInside)

                  解决方案

                  使用 UIButton(type buttonType: .system) 而不是 UIButton() 来初始化按钮.

                  当您使用后者时,它不会正确设置按钮突出显示,因为默认按钮类型是 UIButtonType.custom,它旨在作为没有任何默认样式或突出显示行为的空白板.

                  注意,来自 Apple 的 UIButton 文档:p><块引用>

                  按钮的类型定义了它的基本外观和行为.您指定使用 init(type:) 方法在创建时按钮的类型或在您的故事板文件中.创建按钮后,无法更改它的类型. 最常用的按钮类型是自定义和系统类型,但在适当的时候使用其他类型.

                  My UIButton instance is not highlighting when pressed. I'm pretty sure my code is correct. This only happens in this specific class that I am using. I'm guessing because the function has been overridden by a protocol that I am conforming to.

                  I want to make the UIButton highlight the default way, but I have to do it manually. How can I force highlight the button when pressed, and what are the default settings for it (in terms of colour), so that it is consistent with all the other buttons?

                  Here is my current code:

                      let backButton = UIButton()
                      backButton.setTitle("back", for: .normal)
                      backButton.setTitleColor(UIColor.black, for: .normal)
                      backButton.adjustsImageWhenHighlighted = true
                      RevealBar.addSubview(backButton)
                      backButton.snp.makeConstraints { (make) -> Void in
                          make.center.equalTo(RevealBar)
                          make.width.equalTo(RevealBar)
                          make.height.equalTo(RevealBar)
                      }
                  
                      backButton.addTarget(self, action: #selector(self.goBack), for: .touchUpInside)
                  

                  解决方案

                  Initialize the button using UIButton(type buttonType: .system) instead of UIButton().

                  When you use the latter it won't properly set up button highlighting because the default button type is UIButtonType.custom, which is intended as a blank slate without any of the default styling or highlighting behaviour.

                  Note, from Apple's UIButton documentation:

                  A button’s type defines its basic appearance and behavior. You specify the type of a button at creation time using the init(type:) method or in your storyboard file. After creating a button, you cannot change its type. The most commonly used button types are the Custom and System types, but use the other types when appropriate.

                  这篇关于按下时 UIButton 不突出显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:iOS:将 Exclusive Touch 设置为视图中的所有按钮 下一篇:iOS - 设置 UIButton 背景颜色只为角落着色

                  相关文章

                    <bdo id='GQmfh'></bdo><ul id='GQmfh'></ul>
                  1. <legend id='GQmfh'><style id='GQmfh'><dir id='GQmfh'><q id='GQmfh'></q></dir></style></legend>
                  2. <tfoot id='GQmfh'></tfoot>

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

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