1

If I press & hold a UIButton, the pressed button is rendered; if I press quickly, the UIButton segues to its targeted ViewController. How do I achieve the press & hold effect on a button pressed quickly in Objective-C?

Button Pressed Quickly:

enter image description here

Button Pressed & Held:

Button Pressed & Held

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Eric
  • 893
  • 10
  • 25
  • Would a `UILongPressRecognizer` and custom code for modifying the appearance work? – saagarjha Oct 20 '15 at 01:11
  • Thanks, @ILikeTau. Could you elaborate in a post? What custom code do you have in mind? – Eric Oct 20 '15 at 04:50
  • You button, is it a subview to anything? is it a subview to a `UIScrollView`? – Ty Lertwichaiworawit Oct 20 '15 at 09:21
  • Thanks, @tnylee... No, it is not ;) It is a button in a cell for UITableView. I just want to enable the "pressed" effect long enough to give the user the right feel. – Eric Oct 20 '15 at 21:07
  • The reason our button is delayed to highlight is because the UIScrollView in your UITableView. Have a look at this question and answers http://stackoverflow.com/questions/19256996/uibutton-not-showing-highlight-on-tap-in-ios7/26049216#26049216 Good luck! – Ty Lertwichaiworawit Oct 20 '15 at 21:30
  • [Here's](http://stackoverflow.com/questions/9688139/uilongpressgesturerecognizer-stop-handle-without-stop-touching) an example. Whenever the long press is recognized just highlight the button. – saagarjha Oct 21 '15 at 05:41

2 Answers2

0

just use

myButton.highlighted = Yes
Appi
  • 54
  • 5
0

Try this,

  [myButton setBackgroundImage:[UIImage imageNamed:<Normal - Image>] forState:UIControlStateNormal];
  [myButton setBackgroundImage:[UIImage imageNamed:<Highlight - Image>] forState:UIControlStateHighlighted];
Manishankar
  • 327
  • 1
  • 12