0

I have the following code:

deleteAllButton.setTitle("Delete", forState: .Normal)
        deleteAllButton.titleLabel?.numberOfLines = 2
        deleteAllButton.setTitleColor(UIColor.blackColor(), forState: .Normal)
        deleteAllButton.titleLabel?.font = UIFont.systemFontOfSize(keyboardFontSize)
    //  deleteAllButton.addTarget(self, action: #selector(deletekeyPressed), forControlEvents: .TouchUpInside)

        let deleteLPGR = UILongPressGestureRecognizer(target: self, action: #selector(deleteButtonLongPress))
        deleteLPGR.minimumPressDuration = 0
        deleteLPGR.delaysTouchesBegan = true

        deleteAllButton.addGestureRecognizer(deleteLPGR)

Normally when a UIButton is pressed the text automatically changes color to indicate it is in a "pressed" state. However, since I have added the long press gesture recognizer the button does not indicate that it is in a "pressed" state.

How can I still allow a touch event to go through to the button so the user feels like the button is infact "pressed"?

Foobar
  • 7,458
  • 16
  • 81
  • 161

2 Answers2

0

I think you don't need to add gesture recognizer.

just try to set titlecolor for state highlited and it should work

deleteAllButton.setTitleColor(UIColor.redColor(), forState: .Highlighted)

hope this will fix your issue.

Kuntal Gajjar
  • 792
  • 6
  • 12
0

Just change deleteLPGR.minimumPressDuration = 0 to deleteLPGR.minimumPressDuration = 1 then you can notice the color change when you press

无夜之星辰
  • 5,426
  • 4
  • 25
  • 48