UIBarButtonItem black instead of white - iphone

I have that Navigation Controller and I'm adding 1 button by code this way:
UIBarButtonItem *configButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:#"config.png"] style:UIBarButtonItemStyleBordered target:self action:#selector(showConfigWindow)];
self.navigationItem.leftBarButtonItem = configButton;
It's working right but the icons are black instead of white!!
If I use this:
UIBarButtonItem *configButton = [[UIBarButtonItem alloc] initWithTitle:#"Settings" style:UIBarButtonItemStyleBordered target:self action:#selector(showConfigWindow)];
The text is showed properly in white.
The icons are ok cause I'm using them through interface builder and they show right.

UIBarButtonItem renders images in grayscale according to the images alpha value. So, if your image is fully opaque, then it will always render black, no matter what color the source image is, but if your image is transparent, it will render some shade of grey.
In order to render it fully white, or a color, you need to create a custom UIBarButtonItem. See Can I have a UIBarButtonItem with a colored image? for details

Related

Horizontally repositioning a UIBarButtonItem

Is it possible to reposition a UIBarButtonItem that's in a UINavigationBar horizontally? I've seen the barButtonItem setBackgroundVerticalPositionAdjustment:forBarMetrics: method (but that's for vertical positioning), and I know how to do it if I make it a custom button, but how do I take a UIBarButtonItem with the style UIBarButtonItemStyleBordered and horizontally reposition it (that is, move it left or right)?
Thanks in advance!
You can create a fixed size button as a 'filler' and add that to beside your existing button:
UIBarButtonItem *fixedSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
(Then set the width to your desired value)

Changing colour of NavigationBar and Barbutton

I have a UINavigationBar, and the colour of it is purple. I have added a uibarbutton of the left of it. It too is purple, But what i want it to look is black.
1.) I only need the navigationbar to remain purple, everything else uibarbutton, navigation back button (when we go from one view to another we get a arrow shaped back button) should be black.
I used the interface builder to change the colour of the uibarbutton (setTint), but when i ran it on my iOS 4.3 device it still appears as purple.
I tried cleaning, building and re-installing the app nothing hapence.
Just set it up like this
// Loads the view
-(void)viewDidLoad
{
[super viewDidLoad];
self.navigationController.navigationBar.tintColor = [UIColor blackColor];
self.navigationItem.leftBarButtonItem = [UIBarButtonItem* settings = [[UIBarButtonItem alloc] initWithTitle:#"Settings" style:UIBarButtonItemStylePlain target:self action:#selector(settingsButtonEvent:)]];
[self.navigationItem.leftBarButtonItem setTintColor:[UIColor redColor]];
// some more code for your view
}
You can't set a different tintColor for both objects, but you can set an image as the button background.
I hope it helps you!

How to add an image on UINavigationBar

How do i add a small image on a UINavigationBar ? It should display in front of the title. Its small and 40X40 pixel in size.
noteL: I don't want to add an image to the background to add this tiny image. Furthermore this should work for both iOS4 and 5
On a Navigation bar you can set both right and left buttons like this:
UIImage * myIcon = [UIImage imageNamed:#"icon.png"];
[self.navigationItem setLeftBarButtonItem:[[UIBarButtonItem alloc] initWithImage:myIcon
style:UIBarButtonItemStyleBordered target:self action:#selector(someAction:)]];
To the right button just message setRightBarButtonItem

UIBarButtonItem normal and pressed states switched?

I created a toolbar with a translucent black style like so:
UIToolbar *toolbar = [UIToolbar new];
toolbar.barStyle = UIBarStyleBlack;
toolbar.translucent = YES;
I created a button item for it:
UIBarButtonItem *buttonItem = [[UIBarButtonItem alloc] initWithImage:nil
style:UIBarButtonItemStyleBordered
target:self
action:#selector(mySelector:)];
I noticed that the button when in normal state appears light grey and turns to full black only when I press on it. This seems to be the opposite of how it should function (e.g. Photo app). I'd like it do be black in normal state and lighter when pressed. What am I missing?
Change the barstyle to UIBarStyleBlackTranslucent, as dumb as it sounds, and I believe it returns it to normal.

UIBarButton does not have a 'press' animation

I have a UIView that I am loading and it has a navigation bar with a 'Done' barButton. When I leave the navigation bar the default color, everything is fine. When I make it have a black tint, the 'Done' button works fine but it does not have the pressing animation that buttons usually have. It doesn't look as thought the button is being pressed. Does anyone know why this is?
self.navigationController.navigationBar.tintColor = [UIColor blackColor];
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc]
initWithTitle: NSLocalizedString(#"Done", #"")
style:UIBarButtonItemStyleDone
target:self
action:#selector(donePressed:)]
autorelease];
Thank you so much!
[UIColor blackColor] does not supply a second color for the push effect. Your best best bet is to use darkGreyColor on the navigationBar or if you really need black then you'll have to animate this yourself.
I've heard that the reason black doesn't have a second color is because there is no color darker than black.