Search code examples
rubymotion

Button as a subview of a label does not register clicks


If i create a button as a subview of a label, when i click the button it does not register, the a_share method is never called. How can i create a subview that can be clicked?

button =  UIButton.buttonWithType(UIButtonTypeRoundedRect)
button.setFrame [[ 250, 536 ], [ 120, 120 ]]
button.styleClass = 'browse_share'
button.tag = 3 
button.addTarget(self, action: "a_share:",
                    forControlEvents:UIControlEventTouchUpInside)
label.addSubview button

....

def a_share
  PM.logger.debug "share"
  PM.logger.debug sender.tag
end

Solution

  • Make sure to turn on user interaction for the label, otherwise it won't pass along any taps/gestures:

    label.userInteractionEnabled = true