title: Gray Overlay on a custom UIButton getting displayed
body: <p>I have created a <em>custom UIButton</em> for an <em>iOS 4.3+ application</em>. I wanted to make the background image stretch, so I  and used the following methods to set its background image: </p>
  
  <pre><code>[myButton setBackgroundImage:[[UIImage imageNamed:myImagePath]  stretchableImageWithLeftCapWidth:leftStretchValue topCapHeight:topStretchValue] forState:UIControlStateNormal]
  [myButton setBackgroundImage:[[UIImage imageNamed:myHighlightedImagePath]  stretchableImageWithLeftCapWidth:eftStretchValue topCapHeight:topStretchValue] forState:UIControlStateHighlighted]
  [myButton setBackgroundImage:[[UIImage imageNamed:mySelectedImagePath]
  stretchableImageWithLeftCapWidth:eftStretchValue topCapHeight:topStretchValue] forState:UIControlStateSelected]
  </code></pre>
  
  <p>I have added an event handler to the custom button </p>
  
  <pre><code>[myButton addTarget:self action:@selector(buttonHighlighted:) forControlEvents:UIControlEventTouchDown];
  
  [myButton addTarget:self action:@selector(buttonSelected:) forControlEvents:UIControlEventTouchUpInside];
  </code></pre>
  
  <p>In the above mentioned methods, I have set the selected and the highlighted state of the button accordingly. I have changed the frame of the UIButton to adjust the dimensions of an irregular image <em>(mySelectedImage and myHighlightedImage, neither of which is a rectangle)</em>, so that it gets aligned properly along with myImage.</p>
  
  <pre><code>- (void) buttonSelected {
  myButton.selected = !myButton.selected; //setting the selected property to NO in the     viewDidLoad
  
  //code to change the frame of the UIButton to accomodate the irregular image
  }
  
  
  - (void) buttonHighlighted {
  myButton.highlighted = YES;
  }
  </code></pre>
  
  <p>The problem I am facing is that when I select myButton, <em>a gray color overlay</em> is displayed on myImage for a very short time before the images myHighlightedImage and mySelectedImage are displayed as its background. I have set the <em>background color of myButton as clearColor</em>, thinking that might be the reason, but it is not getting solved. </p>
  
  <p>What could be the possible issue... ? </p>