ios - What's the simplest way to receive tap events on a disabled UIButton? -


i have uibutton on form, , want put in disabled state when form incomplete. however, still want able detect if user attempts press button in disabled state interface can let user know required fields on form not filled-in yet (and perhaps scroll field , point out, etc.).

there doesn't seem straightforward way this. tried attaching uitapgesturerecognizer uibutton doesn't respond when button in disabled state.

i'd avoid subclassing uibutton if possible, unless it's way.

create fallback button. put behind main button. set background , text colors [uicolor clearcolor] ensure won't show up. (you can't set alpha 0 because makes ignore touches.) in interface builder, fallback button should above main button in list of subviews, this:

buttons in subview list

give same frame main button. if you're using autolayout, select both main , fallback buttons , create constraints keep 4 edges equal.

when main button disabled, touches pass through fallback button. when main button enabled, catch touches , fallback button won't receive any.

connect fallback button action can detect when it's tapped.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jquery - Keeping Kendo Datepicker in min/max range -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -