Button Highlight in Xcode - swift

I'm trying to display a second button image when the button is tapped. The second image is displaying but the button gets highlighted and it doesn't look very good. How do I get it to show the second image without highlighting it?

button.setBackgroundImage(IMAGE, forState: UIControlState.Normal)

Related

iOS custom button can't detect touch up on time

I am new to iOS dev, in android for one minute I make custom button with two images normal and hover. I don't know in iOS swift how to do that, few days I am trying, I try but I can't catch touch so I can switch images for non click and click state. If I do that with button there are some delays for touch up and it's not good. I also try with imageView but it's doesn't work. Any help with this?
Just set different images for the button states (for highlighted state and normal state)
button.setImage(UIImage(named: "normal-img"), for: .normal)
button.setImage(UIImage(named: "dark-img"), for: .highlighted)

changing an button image of a tableview

I have been trying to solve a problem, but cannot seem to find a solution.
I have a tableviewcell which contains a button. the button has an image set to it. I would like to change the image when the button is pressed, but I am lacking the proper code for this and where the code needs to be inserted (either in the code inside of tableviewcontoller or tableviewcell file).
I know that the normal code is: self.practicePlayButton.setImage(UIImage(named: "play4.png"), forState: .Highlighted)
for changing the buttons... But I seem to be stumped here.
self.practicePlayButton.setImage(UIImage(named: "play4.png"), forState: .Highlighted)
Replace this...
self.practicePlayButton.setImage(UIImage(named: "play4.png"), forState: .Selected)

Change UINavigationBar button image

I am trying to replace the image displayed in my right navigation bar button when it is tapped.
At the moment what seems to be happening is that it is not replacing the button, but trying to set it while the old one still exists. This leads to a strange effect as you can see:
It's a compass image, so there should only be one circle, but as you can see three are appearing.
This is my code:
let backImg: UIImage = UIImage(named: "Compass.png")!
navButton.setBackgroundImage(backImg, forState: .Normal, barMetrics: .Default)
Is there a way to remove the existing one and replace it with the new one?
Thanks.
It sounds like perhaps you are setting the UIBarButtonItem's backgroundImage when what you really want to set is its image. Thus you end up seeing both of them.

Animate button when pressed and release

In many games and apps I have seen when you click on something, the button image change and while your finger is still on the botton and move it from the button, the image change again and the button is not clicked
In spriteKit I normaly do
gave the button a unique name
in touchesBegan I use nodeInPosition and then check the name of the node
if the names match some action is run
In ViewController
creat the button in the interface builder
creat outline and IBAction and inside of the method some action is run
if the button is made programmatically I use addTarget()
But I don't know how to animate the button when is pressed/hovered and release(return to default state) when the finger is not on button
You can set two images to the button for the highlighted and normal state like this
button.setImage(imageUnhighlighted, forState: UIControlState.Normal)
button.setImage(imageHighlighted, forState: UIControlState.Highlighted)

changing the colour of Button

how can I change the button colour when ever I click that button please help me out
In the action which is executed, when you click the button just add the following line:
button.backgroundColor = [UIColor randomColor];
This gives the button a random color everytime you click it. ;-)