Reputation: 1566
I want to have the accessibilityLabel
of a UIButton to be one value when not selected
, and one value when selected
. What's the best way to do this?
Upvotes: 4
Views: 2790
Reputation: 100632
My instinct is to answer: subclass UIButton
and check self.selected
within an overridden accessibilityLabel
.
But you could also take advantage of the fact that UIControl
s use the [add/remove]Target
semantics so they can post changes of state to arbitrarily many targets, not just a single delegate. You could create and attach a target that pushes a new accessbilityLabel
on demand. If you drop down to the runtime level and use objc_setAssociatedObject
you could associate the helper with the button directly, giving it the same lifetime and avoiding the need for anybody else to keep a reference to it. You should probably just use UIControlEventAllEvents
rather than trying to write a little implicit table of which events may cause selection to change.
Upvotes: 1