title: Wrong barButton item tint for play/pause buttons built programatically
body: <p>I have a UIToolbar with audio controls. Sometime around iOS 7 upgrade the color of the bar changed and iOS started shading my buttons differently. That introduced a bug where the play and pause buttons which I change programatically don't match the new look of the toolbar:</p>
  
  <p>Toolbar starts out looking fine:</p>
  
  <p><a href="https://i.stack.imgur.com/1qMLK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1qMLK.png" alt="Toolbar starts out looking fine"></a></p>
  
  <p>Now I pressed play so code inserted pause button but wrong color:</p>
  
  <p><a href="https://i.stack.imgur.com/V4Bdo.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/V4Bdo.png" alt="Now I pressed play so code inserted pause button but wrong color"></a></p>
  
  <p>Now I pressed pause and code inserted play button, again with wrong color:</p>
  
  <p><a href="https://i.stack.imgur.com/NHCXU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NHCXU.png" alt="Now I pressed pause and code inserted play button, again with wrong color"></a></p>
  
  <p>I want the play and pause buttons to have that same dark look as the other buttons. I assume I have to do something differently when building the replacement buttons. The raw icon images are all that lighter color, but iOS toolbar seems to be automatically recoloring to darker color from the storyboard, as seen in first screenshot.</p>
  
  <p>Here's the code I use to build the buttons:</p>
  
  <pre><code>- (UIBarButtonItem *) makeBarButton: (NSString *) imageName action:(SEL)targetAction
  {
      UIImage* image = [UIImage imageNamed:imageName];
      CGRect frame = CGRectMake(0 - 20, 0 - 20, image.size.width + 20, image.size.height + 20);
      UIButton *button = [[UIButton alloc] initWithFrame:frame];
      [button addTarget:self action:targetAction forControlEvents:UIControlEventTouchUpInside];
      [button setImage:image forState:UIControlStateNormal];
      [button setShowsTouchWhenHighlighted:YES];
      return [[UIBarButtonItem alloc] initWithCustomView:button];
  }
  
  - (void) setAsPlaying:(BOOL)isPlaying
  {
      self.rootViewController.playing = isPlaying;
  
      // we need to change which of play/pause buttons are showing, if the one to
      // reverse current action isn't showing
      if ((isPlaying &amp;&amp; !self.pauseButton) || (!isPlaying &amp;&amp; !self.playButton))
      {
          UIBarButtonItem *buttonToRemove = nil;
          UIBarButtonItem *buttonToAdd = nil;
          if (isPlaying)
          {
              buttonToRemove = self.playButton;
              self.playButton = nil;
              self.pauseButton = [self makeBarButton:@"icon_pause.png" action:@selector(pauseAudio:)];
              buttonToAdd = self.pauseButton;
          }
          else
          {
              buttonToRemove = self.pauseButton;
              self.pauseButton = nil;
              self.playButton = [self makeBarButton:@"icon_play.png" action:@selector(playAudio:)];
              buttonToAdd = self.playButton;
          }
  
          // Get the reference to the current toolbar buttons
          NSMutableArray *toolbarButtons = [[self.toolbar items] mutableCopy];
  
          // Remove a button from the toolbar and add the other one
          if (buttonToRemove)
              [toolbarButtons removeObject:buttonToRemove];
          if (![toolbarButtons containsObject:buttonToAdd])
              [toolbarButtons insertObject:buttonToAdd atIndex:4];
  
          [self.toolbar setItems:toolbarButtons];
      }
  }
  </code></pre>
  
  <p>Appreciate your help with this. </p>