How can I prevent a UIButton from highlighting when pressed? - iphone

When an UIButton is pressed, the normal situation is that it will be highlighted i.e. a shadow like layer will cover the image. Is there a way to prevent this from happening? Is there an attribute to handle this?

You normally don't press a button with Xcode, you use your finger (or mouse). But nitpicking aside: adjustsImageWhenHighlighted set to NO will do the trick.

If you make a custom subclass of the UIButton you can override setHighlighted:(BOOL)highlighted to do nothing
- (void)setHighlighted:(BOOL)highlighted
{
return;
}

You can also achieve this through Interface Builder. Uncheck "Highlighted Adjusts Image" in the Attributes inspector.

Related

Custom UIBarButtonItem highlight issue

I have a toolbar with 5 buttons.
4 of them are regular bar button items and one of them is a custom one (A 'UIButton' inside a 'UIBarButtonItem').
I noticed that when I click between the regular buttons (not exactly on them), one of them (the closest one) still recieves the click event and is being highlighted (which is what I want).
But the custom bar button item does not show this behaviour.
When I tap between it and one of the regular buttons neither of the 2 receives the touch event. This probably because the UIButton is the one the gets the click event. Is there a way to add a touch event the containing bar button item as well? Or perhaps another way to solve this?
Thanks!
button.userInteractionEnabled = YES; I believe is the answer.
One solution might be that you create image of same as bar button item and assign to UIButton as background image, this will solve your issue.
Hope this helps you....
Solved it!
I added another UIView to the UIBarButtonItem and then I added the UIButton to the UIView.
I added a touch gesture to the UIView (And also kept the original touch event of the UIButton) that expanded the area that you can touch the button which solved the problem.

Disable UIButton blue color when Touch event occurs

When my button is pressed, I don't want it's appearance to change. It changes blue while I touch it. I tried going into IB and unchecking "Highlighted adjusts image" but that didn't seem to change anything. I also have "Shows touch on highlight" unchecked. How do I disable this? Thanks for any input.
This solution isn't neat, but it does what you want.
Basically, you create an action method called deselect. And, depending on how little you want it to highlight, you hook several actions up to it. The easiest is just to hook up touch down, touch up inside and outside. However, if you want to insure that even if the user drags it doesn't get highlighted, you also hook it up to touch drag inside and outside.
The method should look like this:
- (IBAction)deselect:(id)sender {
[sender setHighlighted:NO];
}
Hope that helps!

Disable touch animation in UIButton in iPhone

I want to disable the animation of button is touch down or selection. I want to mimic the feature that selection is happening on label. I am comfortable with the properties of button compare to uilabel because i can give my background image and it also help me in more issues.
Please help me in this?
I think what you need is to unselect the "Highlighted adjusts image" option in Interface Builder:
Disable the user interaction of your button.
myButton.userInteractionEnabled = NO;
2018 people, Swift 4.0:
Setting the button's adjustsImageWhenHighlighted property worked. Need this in my custom UITabBarController (e.g. large center tabBarItem).
set your button type as custom.
myButton.buttonType = UIButtonTypeCustom;

uibutton property to avoid highlights

At the time of click a button it's highlighted. While click the button i want to avoid the highlighting of button.
In my Application background image for the button is square shape if i'm click the button it shows square outline of the button.but my button is customtype only....
Please help me out to solve this....
Thank you
Renya
Try setting button's adjustsImageWhenHighlighted property to NO
set adjustsImageWhenHighlighted property to YES...
it will avoid the highlight of UIButton
If you are creating button using Interface Builder..
Inside the button Attribute Inspector ..
On the top .. there is drop down box.. which has different states of the button
like Default, Highlighted, Selected etc.. you can set Button's behavior here..
Did you try adding :
[ homebut setHighlighted:NO ];
?

How do I programmatically make clicking on a UIImageView do something on the iPhone?

I have programmatically added a UIImageView. How do I make it send a message to my controller when the users clicks it, sending itself as the only parameter?
I wouldn't use a UIImageView unless there was some other compelling reason. I'd just use a custom UIButton and use the UIImage as its background.
Create a new class that extends UIImageView and use that.
In your class, override the touch events - touchesBegan, touchesEnded and/or touchesMoved as appropriate
From those methods, call back to a method on the controller.
I'd just put a custom button over the UIImage view, and use normally - buttons with Custom style are invisible and so will not obscure the image. It's also a great way to turn regions of text into clickable areas as well.
Or, you could assign the custom image as a graphic background for the button.
just put a button over the imageview, with the Alpha attribute set to 0.10 or less.
you can capture the button's tap event but almost cannot see it.