Search code examples
iosxcodeuibarbuttonitem

Navigation Bar Button Item Tint


Is it possible to drag a navigation bar button item to the navigation bar, use an image, and NOT have tint applied so that the original image appears as intended? Or is this only possible by adding nav bar button items via code?

Example: My dark background nav bar has white as the default tint, but I have an orange image icon I want to appear for one of the buttons. If I drag a bar button item & set the image, it appears white. Can I change (or remove) the tint for this one button? Or, do I need to forget the visual editor and create this button programmatically to control the tint?


Solution

  • If you want to keep the original colors of the image, you have to do it in code:

    [button setImage:[[UIImage imageNamed:@"imageName.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
    

    If you want to overwrite the tint color of your button (e.g.: orange only) you can achieve that inside your storyboard. Just set the tint color of your Bar Button Item inside Xcode's Attributes Inspector to the desired color:
    Xcode Screenshot