UIButton background color for highlighted/selected state issue
<p>I've a <code>UIButton</code> and I've created an extension to add background color for different state. </p>

<p><strong>I'm using the following code:</strong></p>

<pre><code>extension UIButton {

    func setBackgroundColor(color: UIColor, forState: UIControlState) {

        UIGraphicsBeginImageContext(CGSize(width: 1, height: 1))
        CGContextSetFillColorWithColor(UIGraphicsGetCurrentContext(), color.CGColor)
        CGContextFillRect(UIGraphicsGetCurrentContext(), CGRect(x: 0, y: 0, width: 1, height: 1))
        let colorImage = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()

        self.setBackgroundImage(colorImage, forState: forState)
    }
}


// Set Button Title and background color for different states
    self.donateButton.setBackgroundColor(UIColor.redColor(), forState: .Normal)
    self.donateButton.setTitleColor(UIColor.whiteColor(), forState: .Normal)
    self.donateButton.setBackgroundColor(UIColor.greenColor(), forState: .Highlighted)
    self.donateButton.setTitleColor(UIColor.whiteColor(), forState: .Highlighted)
    self.donateButton.setBackgroundColor(UIColor.greenColor(), forState: .Selected)
    self.donateButton.setTitleColor(UIColor.whiteColor(), forState: .Selected)
</code></pre>

<blockquote>
  <p>My Problem is that it is not picking up proper <code>UIButton</code> background color and title color for highlighted/selected state.</p>
</blockquote>

<p><a href="https://i.stack.imgur.com/aFjgX.png" rel="noreferrer"><img src="https://i.stack.imgur.com/aFjgX.png" alt="Normal state"></a>
<a href="https://i.stack.imgur.com/jPqb2.png" rel="noreferrer"><img src="https://i.stack.imgur.com/jPqb2.png" alt="Highlighted state"></a></p>