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)
Related
I have a button that acts as a switch: I check the current state of the variable (stored in used defaults) and attribute it in viewDidAppear
When I press the left button (ignore the right one) it is acts as it should - swapping out 2 UIImages on button's UIImageView
but as soon as button goes out of focus - button switches image back to the default one. if no default image is specified in IB - button just goes to blank image.
How can I ensure button keeps the image after is goes out of focus? Do I need to implement additional focus delegate methods or something? I'm new tvOS and some things just don't make sense to me yet.
Doh, it appears you cannot just swap out UIImage on UIImageView property and have to use a button setter for such matter:
button.setImage(UIImage, forState: UIControlState.Normal)
It works fine this way
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)
So, I want to add a button over existing image, but what I want is - when I tap on map (in this case), I want this red button to show up at the place where I tapped. I want it in SWIFT.
https://www.dropbox.com/s/3oei04rsmf2xh99/Screenshot%202015-02-20%2013.42.17.png?dl=0
I've gotten Tweet sheets to appear in my app, but I'd like to spawn them only when a user presses the particular "Tweet" button in a UIActionSheet.
Currently, my UIActionSheet is being shown in the main view after the user presses a Rounded Rect Button. I would like to change this button to be Apple's "standard" share method, which is using the button with the square image and the arrow jumping out of it, as shown below
Where could I find the image for the button to do this, or is the button already built into XCode?
I hope I'm being clear enough.
Thank you.
You have to just create toolbar item with Bar Button Item. In Attributes Inpector choose 'Action' type of your button.
Attach selector/method from your rounded rect button to this button.
HTH!
I want to drag and drop UIbutton in my app like iPhone main screen icons.
I can do this but while clicking the button it should perform an action. But this action is also called while dragging the button. I am using UIControlEventTouchDown for touch action and UIControlEventTouchDragInside for dragging the button.
Maybe you can use UIControlEventTouchUpInside for this action instead touch down.
In UIControlEventTouchDragInside you may change the shared variable named like "dragPerformed" to YES, and then, if it is NO perform click button action in UIControlEventTouchUpInside, if YES - do nothing (that is drag) and turn it to NO