How do I show/hide a UIBarButtonItem?

前端 未结 30 2264
执念已碎
执念已碎 2020-11-28 01:18

I created a toolbar in IB with several buttons. I would like to be able to hide/show one of the buttons depending on the state of the data in the main window.

30条回答
  •  执念已碎
    2020-11-28 02:00

    iOS 8. UIBarButtonItem with custom image. Tried many different ways, most of them were not helping. Max's solution, thesetTintColor was not changing to any color. I figured out this one myself, thought it will be of use to some one.

    For Hiding:

    [self.navigationItem.rightBarButtonItem setEnabled:NO];
    [self.navigationItem.rightBarButtonItem setImage:nil];
    

    For Showing:

    [self.navigationItem.rightBarButtonItem setEnabled:YES];
    [self.navigationItem.rightBarButtonItem setImage:image];
    

提交回复
热议问题