Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/111.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 轻触时,UIButton不会突出显示_Ios_Swift_Uibutton_Highlight - Fatal编程技术网

Ios 轻触时,UIButton不会突出显示

Ios 轻触时,UIButton不会突出显示,ios,swift,uibutton,highlight,Ios,Swift,Uibutton,Highlight,我知道有很多关于这个主题的答案,但我尝试了所有的方法,只是不明白代码中出了什么问题。我只需在顶部栏中添加按钮,并尝试点击但不高亮显示动画触发器 请看此视频: 这是我的密码 if rightFisrtBtn != nil { btnfirst = UIButton(type: UIButtonType.custom) btnfirst.tag = tagTopBar.btnfirst.rawValue btnfirst.translatesAutoresizingMaskI

我知道有很多关于这个主题的答案,但我尝试了所有的方法,只是不明白代码中出了什么问题。我只需在顶部栏中添加按钮,并尝试点击但不高亮显示动画触发器

请看此视频:

这是我的密码

if rightFisrtBtn != nil {
    btnfirst = UIButton(type: UIButtonType.custom)
    btnfirst.tag = tagTopBar.btnfirst.rawValue
    btnfirst.translatesAutoresizingMaskIntoConstraints = false
    btnfirst.imageView?.contentMode = UIViewContentMode.scaleAspectFill
    btnfirst.titleLabel?.font = fontWithSize


    if rightFisrtBtn! is String {
        btnfirst.setTitle(rightFisrtBtn as? String, for: .normal)
        btnfirst.setTitleColor(UIColor.black, for: .normal)
        btnfirst.setTitleColor(UIColor.white, for: .highlighted)

        topView.addSubview(btnfirst)

        topView.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:[btnfirst(width)]-[btnSecond]", options: [], metrics: ["width":btnfirst.intrinsicContentSize.width + 10.0], views: ["btnfirst":btnfirst,"btnSecond":btnSecond]))

        topView.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|-(25.0)-[btnfirst]-(gap)-|", options: [], metrics: ["gap":10.0], views: ["btnfirst":btnfirst]))

    } else if rightFisrtBtn! is UIImage {
        btnfirst.setImage(rightFisrtBtn as? UIImage, for: .normal)
        btnfirst.contentHorizontalAlignment = UIControlContentHorizontalAlignment.center
        topView.addSubview(btnfirst)

        topView.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:[btnfirst(width)]-[btnSecond]", options: [], metrics: ["width":btnfirst.imageView?.image?.size], views: ["btnfirst":btnfirst,"btnSecond":btnSecond]))

        topView.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|-(25.0)-[btnfirst]-(gap)-|", options: [], metrics: ["gap":5.0], views: ["btnfirst":btnfirst]))
    }

    btnfirst.addTarget(self, action: #selector(self.btnTopbarFilter_Clicked(_:)), for: .touchUpInside)

}

如果我能理解您的查询,您希望在点击按钮时显示按钮高亮显示状态的属性

在这种情况下,在实现按钮的目标操作时,请使用UIButton实例的isSelected属性:

func btnTopbarFilter_单击u发件人:ui按钮{

sender.isSelected = !sender.isSelected

}

使用btnfirst.showsTouchWhenHighlighted=true突出显示触摸。@RamkrishnaSharma感谢您的回复,但我需要默认选择的事件,该事件在图像未被触摸时显示,whenhighlighted我只需在顶部栏中添加没有意义的按钮。不能将UIButton直接放入顶部栏中。我没有看到任何代码可以使用btnfirst执行任何操作。请显示它是如何进入界面的。@matt我没有使用UINavigationBar。我做了顶栏和视图。请看视频