开发者

Hiding a UITabBar programmatically

开发者 https://www.devze.com 2023-04-11 13:07 出处:网络
I have a UITabBar which controls multiple Views and I would like to hide one of them from the release build, but still keeping it in the project as I need 开发者_StackOverflow中文版it for testing purp

I have a UITabBar which controls multiple Views and I would like to hide one of them from the release build, but still keeping it in the project as I need 开发者_StackOverflow中文版it for testing purposes. How can I do this programmatically? It should not be visible to the user at all. Thanks!


Yes you can do this. Try [yourTabBar setHidden:YES]; also [yourTabBar setAlpha:0];

One other best thing I do, if you are using Interface builder to develop your UI is to move the appropriate UIView (here its UITabBar). out of the main nib (or xib) file. That way you are hiding whatever view you want to hide & at the same time it's part of the build.


After the tabBar is initialized do the following:

NSMutableArray* currentItems = [NSMutableArray arrayWithArray:tabBar.viewControllers];
[currentItems removeObjectAtIndex:itemNumberToRemove];
[tabBar setViewControllers:currentItems animated:NO];

What this does:

It gets the current viewcontrollers held by the UITabBar, removes an item from the array specified by itemNumberToRemove and then puts the items remaining back in the UITabBar.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号