Search code examples
iosobjective-cuibarbuttonitemuitoolbar

UIBarButtonItem - Make it not clickable when just text


So I have a UIToolbar with 4 UIBarButtonItems on it (2 of them being Flexible Space) the middle one is of Style: Plain with a Title set "Settings" and then the far right button is a 'Done' button to close the view.

Everything looks good and works the way I want except for the middle text button is "clickable", it does nothing when you click on it but there is a white glow that appears around the text once it's touched.

The only options you get with a UIBarButtonItem is 'Enabled' which if turned OFF makes the text greyed out.

I was able to almost simulate the way it looks by creating a UILabel and adding as a subview to the UIToolbar but I was wondering if there's a simpler way to doing this.

Thanks


Solution

  • use the customView of UIBarButtonItem, to set an UILAbel as customView. the item will not be clickable.

    UILabel *yourLabel = ...;
    UIBarButtonItem *theBarItem = [[UIBarButtonItem alloc] initWithCustomView:yourLabel];
    

    that's all.