Hi i am trying to make a uibutton to blink automatically. i am aware that there is a function "shows touch on highlight" which blink when user touch but i need my button to blink automatically. Is there any way to do it? Thanks!
First of all: Don't do that!!!
But if you do then you could
set timers or use performSelector ...withDelay: or similar stuff to trigger the switching of the images.
Or make the button transparent and layout it on top of a UIImageView. A UIImageView can be set up with an array of images, rather than a single image only, and a time interval used to swap from one image of the array to the next. See the docs for details. It is pretty straigt forward.
Related
I have seen this in other programs and am trying to replicate it.
I have an image on one of my forms that someone can drag-and-drop an image into. I would like to allow the user to click on that image to pop up another dialog that they could instead select a "stock" image if they choose to.
I don't see an outlet I can use for the click and putting a transparent button over the top would defeat my ability to drag and drop an image on to it.
I realize I could just change the image to a button instead but I prefer to use an image if possible.
How can I make an image clickable?
This is OSX by the way, not IOS.
Quoting from another question:
By default, NSImageView doesn't react to -mouseDown:, or -mouseUp: like other NSControl subclasses (namely NSButton) do.
The solution is given in an answer elsewhere - subclass NSImageView and appropriately handle the click event (as linked).
Drag in the standard NSButton.
Uncheck the Bordered checkbox.
Clear the Title text.
Set the Image (and optionally, the alternate image).
Also, if you are using layout constraints to set button size to image view size, don't forget to set vertical hugging/compression resistance priorities to low values (say 1).
If I have a UIImageView of a circle, how could Core Animation make it disappear like in this question?
How to use CoreAnimation to animate a circle like a clock countdown
Create a CAShapeLayer. Set its path to your “clock” shape. Set it as the layer mask of your image view (e.g. imageView.layer.mask = shapeLayer).
Then you can try using a CAKeyframeAnimation to animate the shape layer's path, but I suspect the results won't be pleasing. Instead you'll probably want to use a CADisplayLink as a timer and update the shape layer's path every time it fires.
What you are looking for is known as a "clock wipe" transition.
David is pointing you in the right direction. I have a sample project on Github that shows exactly what you are looking for:
iOS Core Animation Demo
When you run the app, click on the "Mask Animation" button. It does what you're talking about. It shows an image view with a clock wipe, and then hides it again. It would be a simple matter to switch it around to have the image fully visible at first and then animate a clock wipe to hide it.
I am displaying hundreds of thumbnails in my view . I know default way to handle tap on thumbnail is using UICollectionView delegate method "didSelectItemAtIndexPath" but since its many thumbnails i wanted to look into adding gestures to the screen position so when i tap on a particular spot on the screen, it will handle the event accordingly for that particular thumbnail underneath. I would like to know if it is a good/possible approach?
It would be a hell of a lot easier to use a UICollectionView.
If you need a custom layout then you can subclass UICollectionViewLayout and get some really cool dynamic layouts.
You also get the added bonus of dequeued cells meaning that you get better memory management using it.
You may find UIGestureRecognizer useful. A good tutorial to get you started is here.
I am trying to make an irregular shaped button with the OBShapedButton class. That's ok, created it without any problem, however I need the image to be transparent. So, I just want an area from the image which will be clickable, but the image won't be seen.
I tried setting alphas on image, imageView and on the button itself, however it doesn't work neither way.
How should I do it?
Maybe it could be done by something else, not an UIButton, but unfortunately I didn't find anything on the net that I could understand and use.
Ok, so the easiest way on how to do this is:
Subclass UIButton and add touchesBegan, touchesEnded, touchesMoved,
touchesCancelled.
Then on touchesBegan, hide the image of the button and show the correct image in background.
And finally on touchesEnded or touchesMoved, show again the image of the button.
Hope it will help someone :)
I know it's probably best to have two buttons on top of the image - my problem is the buttons themselves should be invisible, but the text on the buttons should be visible???
EDIT: sorry, found an option 30 secs after posting! If you set button to type to 'Custom', you can get text displaying without anything other than the text....
The UIButton may be not the best solution. If a performance issues occur (animation is not smooth anymore) you should implement your own view and handle tap events (with UIGestureRecognizer for example). But for the first prototype UIButton will be good enough in any case.