简体   繁体   中英

touchUpInside effect for UIBarButtonItem

When left/rightBarButtonItem of UIBarButtonItem is tapped, I do not see the touchUpInside effect. ie 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?

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];

UIBarButtonItem不使用touchUpInside,而是仅具有目标和操作来定义何时激活它们。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM