I'm working on a tic tac toe game where each square is its own button and the image of the button changes when the square is tapped. I have done this by connecting all of the square buttons to the same IBAction @IBAction func buttonPressed(sender: AnyObject)
and by using sender.setImage()
to change the image. The problem is, the images are all blue. I can change this blue to a different color by changing the global tint color, but what I really want is for the O and X images to be different colors. sender.tintColor
throws an error and button.tintColor
, as I have in the code below, just changes the color of one image back and forth every time a square is tapped. I have tried setting the global tint to no color in the File Inspector, but it just goes back to the default blue. Any thoughts?
if activePlayer == 1 {
sender.setImage(UIImage(named: "o-img"), forState: .Normal)
activePlayer = 2
button.tintColor = UIColor.blackColor()
} else {
sender.setImage(UIImage(named: "x-img"), forState: .Normal)
activePlayer = 1
button.tintColor = UIColor.whiteColor()
}
As it turns out, changing the button type from 'System' to 'Custom' removes the tint. Hope that helps someone else who came across the same issue!