Hide UIToolbar UIBarButtonItems

后端 未结 6 1510
[愿得一人]
[愿得一人] 2020-12-03 08:12

I have a UIToolbar that I set up using IB with three buttons, left, middle and right. In some situations I would like to not display the middle button. Does anybody know of

6条回答
  •  南笙
    南笙 (楼主)
    2020-12-03 08:37

    Rather than guessing at the index, I added an IBOutlet for the UIBarButtonItem and then removed it by name:

    NSMutableArray *toolBarButtons = [self._toolbar.items mutableCopy];
    [toolBarButtons removeObject:self._selectButton]; // right button
    [self._toolbar setItems:toolBarButtons];
    

    And of course it helps to connect the outlets in the designer :)

提交回复
热议问题