如何以编程方式在UITabView应用程序中隐藏某些选项卡?
如何修改didFinishLaunchingWithOptions以隐藏某些选项卡,例如
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after app launch.
// Add the tab bar controller's current view as a subview of the window
[self.window addSubview:tabBarController.view];
[self.window makeKeyAndVisible];
return YES;
}我试着添加
for (UIViewController *v in tabBarController.viewControllers )
{
UIViewController *vc = v;
if ([vc isKindOfClass:[FirstViewController class]])
{
FirstViewController *myViewController = vc;
vc.view.hidden = YES;
}
}但它会删除此视图的内容,名为first的选项卡仍会出现。怎么把它也去掉?
发布于 2011-03-28 18:44:18
使用UIView的hidden属性。由于每个视图都继承自UIView,
发布于 2011-03-28 20:01:38
严格地说,你不应该做这样的事情。标签栏的意义在于显示应用程序中令人绝望的部分,而不是上下文相关的部分。对于这类事情,最好使用UIToolBar。试图根据上下文隐藏单独的选项卡可能会让你的应用程序被苹果拒绝。
也就是说,如果你必须这样做,你需要使用UITabBarController的setViewControllers:animated:方法,你不需要对你的FirstViewController本身做任何事情。
类似于:
NSMutableArray* controllers = [myTabBarController.viewControllers mutableCopy];
[controllers removeObjectsInRange: NSMakeRange(0, 1)];
[myTabBarController setViewControllers: controllers animated: YES];发布于 2018-08-16 18:44:54
我同意"Daniel T“标签必须留在适当的位置。
无论如何,我不得不根据web服务修改标签,如果没有记录,就隐藏“配置文件”标签。
作为起点:
1)定制TabBarController创建自定义类
2)实现您的逻辑。(在示例代码中,我甚至更改了图标...基于web设置。。)
/ Created by ing.conti on 6/5/18.
// Copyright © 2018 ing.conti. All rights reserved.
//
import UIKit
class CustomTabBarController: UITabBarController {
override func viewDidLoad() {
super.viewDidLoad()
// by hand:
setupTabBar()
}
final private func setImage(named: String, to: UITabBarItem){
if let image = UIImage(named: named){
to.selectedImage = image
to.image = image
}
}
final func setupTabBar(){
guard var tbis : [UITabBarItem] = self.tabBar.items else{
return
}
// set images, anyway.. so it's ready for future
tbis[0].title = localized("TITLE1")
self.setImage(named: "img1", to:tbis[0])
tbis[1].title = localized("TITLE2")
self.setImage(named: "title2", to:tbis[1])
tbis[2].title = localized("PROFILE")
self.setImage(named: "profile", to:tbis[2])
// for now simply remove controller...
if !LoginManager.shared.logginAllowsProfile(){
self.viewControllers?.removeLast()
}
// as a convenience, select always 2nd:
// self.selectedViewController = self.viewControllers?[1]
}}
https://stackoverflow.com/questions/5457775
复制相似问题