Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Option 1 is indeed possible. Unfortunately it's a painful thing to find the UIView that the UIBarButtonItem creates. Here's how I found it:</p> <pre><code>[[[myToolbar subviews] objectAtIndex:[[myToolbar items] indexOfObject:myBarButton]] addGestureRecognizer:myGesture]; </code></pre> <p>This is more difficult than it ought to be, but this is clearly designed to stop people from fooling around with the buttons look and feel.</p> <p>Note that Fixed/Flexible spaces are <strong>not</strong> counted as views!</p> <p>In order to handle spaces you must have some way of detecting them, and sadly the SDK simply has no easy way to do this. There are solutions and here are a few of them:</p> <p>1) Set the UIBarButtonItem's tag value to it's index from left to right on the toolbar. This requires too much manual work to keep it in sync IMO.</p> <p>2) Set any spaces' enabled property to NO. Then use this code snippet to set the tag values for you:</p> <pre><code>NSUInteger index = 0; for (UIBarButtonItem *anItem in [myToolbar items]) { if (anItem.enabled) { // For enabled items set a tag. anItem.tag = index; index ++; } } // Tag is now equal to subview index. [[[myToolbar subviews] objectAtIndex:myButton.tag] addGestureRecognizer:myGesture]; </code></pre> <p>Of course this has a potential pitfall if you disable a button for some other reason.</p> <p>3) Manually code the toolbar and handle the indexes yourself. As you'll be building the UIBarButtonItem's yourself, so you'll know in advance what index they'll be in the subviews. You could extend this idea to collecting up the UIView's in advance for later use, if necessary.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload