1

I have created a UIButton on the Interface Builder (Main.storyboard). I Connected two actions to the View Controller swift file, as you can see below:

@IBAction func backDownPress(sender: UIButton) {
    backButon.backgroundColor = UIColor.blackColor()
}
@IBAction func backNormalPress(sender: UIButton) {
    backButon.backgroundColor = UIColor.clearColor()
    performSegueWithIdentifier("pushFromRight", sender: self)
}

The top action is a Touch Down, and the bottom is a Touch up Inside.

However, once I try to run the app on either the Simulator or my iPhone, the touch doesn't register. When I try to just put a print line in the action, it also doesn't do anything.

Looking through the rest of my code, I can't find anything like disabling the user interaction, so I don't know why this doesn't work.

3 Answers3

2

Well there are 2 possible solutions to this:

1) The @IBAction is not connected to the button.

2) There is something layered in front of the Button (a view of some kind)

impression7vx
  • 1,728
  • 1
  • 20
  • 50
0

I m guessing you want to change button color when pressed.

1. Subclass UIButton and implement

override var highlighted: Bool {
        get {
            return super.highlighted
        }
        set {
            if newValue {
                backgroundColor = UIColor.blueColor()
            }
            else {
                backgroundColor = UIColor.clearColor()
            }
            super.highlighted = newValue
        }
    }
hariszaman
  • 8,202
  • 2
  • 40
  • 59
0

Assuming your IBAction connections are proper: Check the userInteractionEnabled property for superview as subView's user interaction depends on superview as well. Check this SO link.

Community
  • 1
  • 1
SHN
  • 785
  • 7
  • 23