質問

I have an image that is assigned to the navigationItem.leftBarButtonItem on IOS7. When I get it from the designer it looks fine on the navigation bar's background. But when I implement it in IOS7 it becomes pale and almost disappears.

This is how it's being set up:

UIBarButtonItem *button = [[barButtonItemClass alloc] initWithImage:[UIImage imageNamed:@"nav_menu_icon.png"] style:UIBarButtonItemStyleBordered target:self action:@selector(showLeft:)];
viewController.navigationItem.leftBarButtonItem = button;

This is how it should look (image came from my designer):

enter image description here

And this is how it looks when implemented (on the simulator or a phone):

enter image description here

What's the solution?

役に立ちましたか?

解決

You should set the tint color of the navigation bar to tint all items in the bar.

A nice solution is to use the UIAppearanceprotocol introduced in iOS 5. In you AppDelegate's applicationDidFinishLaunching method put the following code:

[[UINavigationBar appearance] setTintColor: [UIColor whiteColor]];

Note, I am currently not able to try the code.

Cheers!

他のヒント

this works fine for me :

 UIBarButtonItem *customItem = [[UIBarButtonItem alloc] initWithImage:backButtonImage style:UIBarButtonItemStyleBordered target:self action:@selector(backBtnAction)];
    customItem.imageInsets = UIEdgeInsetsMake(0.0, -10, 0, 0);// For adjusting the image
    [customItem setBackgroundVerticalPositionAdjustment:+3.0f forBarMetrics:UIBarMetricsDefault];
    [self.navigationItem setHidesBackButton:YES];// Hide the Default back button before set custom
    [self.navigationItem setLeftBarButtonItem: customItem];

Hopefully, causes might be with the Tint

Try this, may help you ;

// Solve your frame issue.

UIImage * bgImg = [UIImage imageNamed:@"nav_menu_icon.png"];
UIButton *leftButton = [[UIButton alloc] initWithFrame: CGRectMake(x, y, bgImg.size.width, bgImg.size.width)];
viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftButton];

Also change the tintColour to clear colour.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top