Abhinav
Abhinav

Reputation: 38162

touchUpInside effect for UIBarButtonItem

When left/rightBarButtonItem of UIBarButtonItem is tapped, I do not see the touchUpInside effect. i.e. the color of the button should change. Do I need to implement something here?

I am not able to change the color when I put my finger on the right bar button. I do not see any property called background color on UIBarButtonItem. How to achieve this?

Upvotes: 0

Views: 1896

Answers (2)

NWCoder
NWCoder

Reputation: 5266

UIBarButtonItem don't use touchUpInside, instead they only have the target and action to define when they are activated.

Upvotes: 1

WrightsCS
WrightsCS

Reputation: 50707

You cant change the color of the UIBarButtonItem, you need to set the Tint of the UINavigationController that the button is on.

The UIBarButtonItem will inherit the Tint color of the NavBar. You can alternatively change the UIBarButtonStyle to UIBarButtonSystemItemDone to make the button a darker color of the navBar's Tint.

Also, the UIBarButtonItem does not have a touchUpInside method, you can override it's action by setAction:.

Here are some of your options for UIBarButtonItem:

UIBarButtonItem *backButton = [[UIBarButtonItem alloc] init];

    /* make the back button an image */
    [backButton setImage:[UIImage imageNamed:@"anImage.png"]];

    /* change the title for child views */
    [backButton setTitle:@"Go Back!"];

    /* tell the button to do something */
    [backButton setAction:@selector(doSomething:)];

    /* disable the button */
    [backButton setEnabled:NO];

    /* make this button the BACK button for nav controller */
    self.navigationItem.backBarButtonItem = backButton;

    /* create this button on the RIGHT side of the navBar */
    self.navigationItem.rightBarButtonItem = backButton;

[backButton release];

Upvotes: 3

Related Questions