How to register the 'release' of a 'touch' of a button (or simply a 'touch and hold' event)?

Hello all - I’m making my first app, and I’d like to implement an ‘info’ button that simply displays a popup/bubble message (next to it) when a user taps on it, but which disappears when the user releases their tap (i.e. lifts up their finger off from the screen).
It’s just an informative popup of info, that is to be displayed only whilst the user has their finger on the ‘info’ button.

I can get the popup to appear immediately on touch by using a ‘touch down’ event (by Ctrl+dragging the button to the source code to form an ‘IBAction’ link and selecting ‘touch down’ as the event type), but I’d like to be able to perform an action (i.e. to make the popup disappear) when the user lifts off their finger from the button/screen).

Has anyone got any cunning ideas?

(P.S. I’m relatively new to coding… been learning for 2-3 months part time)


You could create a class or an extension to handle the touch events, like this:

class Button: UIButton {
    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        isHighlighted = true
        super.touchesBegan(touches, with: event)

    override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
        isHighlighted = false
        super.touchesEnded(touches, with: event)

    override func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent?) {
        isHighlighted = false
        super.touchesCancelled(touches, with: event)


@FoundationSW - at first glance that code looked a bit scary to me (as I was thinking there might instead be some in-built feature for this)… but actually on second look, I think it actually is just about within my abilities to understand and implement (I had aways been a touch scared of sub-classing anything in xCode, but your code above does actually seem a simple enough thing for me to ‘test the water’ and have my first attempt at sub-classing).
Thanks ever so much Mark - that’s very kind indeed!