How to disable the light that appears when touching a UIBarButtonItem? - iphone

I have a toolbar with a UIBarButtonItem with style: UIBarButtonItemStylePlain.
I wonder how can I disable the light that appears while touching it?
UIButton has showsTouchWhenHighlighted property but there is no such a thing for UIBarButtonItem is there a work-around you might know?

In Interface Builder drag a UIButton to the toolbar. It will create a UIBarButtonItem with a UIButton in it. Set the type of the UIButton to custom. Then you can fully customize the appearence. For example change the text color to white and the background color to transparent and of course disable the highlighting.

You can also drop in a UITextField and make it non-editable.

Related

Change UIToolbar Shadow Color For UIBarButtonItem

I am styling a UIToolbar by changing the tint color of it and the tint color of its UIBarButtonItem subviews. I have it working except that I can't find how to change the the shadow color from a dark color to a light color for the individual bar button items (see example, bar button items look blurry):
How can I change the shadow on the UIBarButtonItem with style UIBarButtonItemStylePlain to be white? I've uploaded a sample project here.
The final solution was to add the buttons as UIButton contained in UIBarButtonItem and include any shadows in the PNG used for the UIButton image.
In the UIBarButtonItem Class Reference there isn't a single mention of the word "shadow"
You use an image for the shadow, not a UIColor
Some source code examples can be found # cocoaControls.com
For the UIBarButtonItem appearance only the 2 images and colors can be changed:
setBackgroundImage:forState:barMetrics:
Sets the background image for a given state and bar metrics.
- (void)setBackgroundImage:(UIImage *)backgroundImage forState:(UIControlState)state barMetrics:(UIBarMetrics)barMetrics
For the UIToolBar:
For adding your own custom shadow look at this StackOverflow
post
For using cocoa-predefined functions look at UIToolBar Class
Reference
setShadowImage:forToolbarPosition:
Sets the image to use for the toolbar shadow in a given position.
(void)setShadowImage:(UIImage *)shadowImage forToolbarPosition:(UIToolbarPosition)topOrBottom
shadowImageForToolbarPosition:
Returns the image to use for the toolbar shadow in a given position.
(UIImage *)shadowImageForToolbarPosition:(UIToolbarPosition)topOrBottom
I don't know what else to say, there isn't a shadow method for the UIBarButtonItem.
I hope this is self explanatory.

How to create custom UIBarButtonItem without glossy effect

I use Three20 to create UIBarButtonItem as shown in this StackOverFlow question:
Custom UIBarButtonItem with quartz
now I what that UIBarButtonItem have no glossy effect and can have different color (light color and dark color).
Do you know how to do it?
UPDATE:
and I would like to do it without using images.
You can always use initWithCustomView on UIBarButtonItem and using it you can basically put in that view what ever you want - TTButton, UIButton, custom UIView, etc...

Tapping on UIBarButtonItem

I want a button tap effect for a UIBarButtonItem. My navigation bar has black tint color:
[self.navigationController.navigationBar setTintColor:[UIColor blackColor]];
So when I tap on any UIBarButtonItem on it, I do not get a button tapping effect. If I change the tint color to some other color like gray, it works. But I want only the black color there in the tint.
When you tap on a button, it color fades and you feel the tapping effect. That is because of touchUpInside action associated with UIButton class but nothing such event is there with UIBarButtonItem. I can get that effect with UIBarButtonItem if I set the Tint color of Navigaiton bar to other than black or dark gray.
Any suggestions.
You can always set your UIBarButtonItem custom view to a UIButton, then youll have whatever effect from UIButton that you like...
I got this done by setting the nav bae style:
myController.navigationBarStyle = UIBarStyleBlackOpaque;

UIBarButtonItem Highlighted Color

I have set a custom tint color for a UINavigationBar (within a UINavigationController) which, in turn, sets an appropriate matching color for the UIBarButtonItems which are inserted into the UINavigationBar. However, when I select a UIBarButtonItem the button turns into (presumably) the highlighted state and presents a different color, which looks quite a bit out and does not nicely match the tint color. Is there a way to change this highlighted state color to a custom color?
Ideally, I would like to just create a category on UIBarButtonItem which changes the highlighted color for all instances of UIBarButtonItem, as this would avoid the need to explicitly subclass UIBarButtonItems and then change every reference in my app to use the subclass (which will be tricky, as I am using some third-party libraries which just use UIBarButtonItem and I don't want to go messing with their implementation).
Any help would be greatly appreciated.
From what I remember from facing a similar issue, UINavigationBar will just take the tintColor and make it darker for the UIBarButtonItem (unless the style is set to BarStyleBlack, in which case it makes it a dull gray).
To do what you ask, I would create a custom UIButton with background images for the different control states that match your color scheme, then use this UIButton as the view for a custom UIBarButtonItem.
UIButton *customButton = [UIButton buttonWithType:...];
//normal_button.png and selected_button.png need to be created by you
[customButton setBackgroundImage: [UIImage imageNamed:#"normal_button.png"] forState:UIControlStateNormal];
[customButton setBackgroundImage: [UIImage imageNamed:#"selected_button.png"] forState:UIControlStateSelected];
UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithCustomView: customButton];
If you want to try and encapsulate this, you could always create a factory or a custom init method on UIBarButtonItem (via a category) and use the above code (with slight modifications).
I am aware that I am not fully addressing your second point on just overriding the control state with a category. I don't know what method to override in UIBarButtonItem to do such a thing, but you may be able to accomplish what you want via method swizzling (http://cocoadev.com/index.pl?MethodSwizzling) once you find out which method you want to exchange.
I should note that I've only ever used swizzling for testing/debugging.
If you're using Interface Builder, drag and drop an UIButton to the navigation's bar right side, and it gets in as a right navigation bar button item. Then, configure different tints for different states of the button, and you're done.
Works in Xcode 10 and Swift 4.

transparent button

Is there a way to make a button transparent without alpha?
To explain: I have a background image on my view. There is also a button with an image background. If the image has a transparent part I see white inside the button's background image.
Is it possible to make the image transparent?
You can set the button type to 'Custom', either in code with: UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; or in IB on the Attributes pane, under Button -> Type -> Custom.
Set the backgroundColor of the button to [UIColor clearColor] and optionally its opaque to NO (Should automatically be applied by setting the background color to transparent).
You want to set the button opaque property to NO.
In InterfaceBuilder, you have a checkbox to do that.