How can I remove a UITabBarItem
from a UITabBar
?
I haven't tried anything, because I haven't found anything from Google searches or the documentation for UITabBar
, UITabBarController
, or UITabBarItem
.
Thanks in advance! :)
How can I remove a UITabBarItem
from a UITabBar
?
I haven't tried anything, because I haven't found anything from Google searches or the documentation for UITabBar
, UITabBarController
, or UITabBarItem
.
Thanks in advance! :)
NOTE: this appears to not work in iOS 11. It was still good in iOS 10.
This is a moderately horrible answer, in my opinion, in part because it's subverting the human interface guidelines, but all the same it seems to work cleanly:
That layers it cleanly on top of the old tabbar, and it maintains its functionality.
UITabBar has an NSArray collection of items. Since the items property is an NSArray and not an NSMutableArray, you'd have to construct a new NSArray from the existing one devoid of the object you want to remove, then set the items property to the new array.
Mike Caron's advice will throw an exception if you intend to modify a tabBar that belongs to a controller.
In this case
self.tabBarItem=nil
will remove it.