如果我们有超过5个选项卡...将第5个选项卡设置为“更多”选项卡..然后单击“更多”选项卡其余选项将显示在表格视图中... 我以编程方式创建了相同的动态选项卡。
但是我没有在更多标签中显示,而是需要它来显示它可滚动。
这是我的标签类。 我有,LoginView,testvc1,testvc2,testvc3,testvc4,testvc5,testvc6,testvc7 viewcontroller。
Loginview(包含按钮) - >点击按钮标签栏打开。
TabBarVC.h
#import <UIKit/UIKit.h>
@interface TabBarVC : UITabBarController
{
UITabBarController *tabController;
}
@property(nonatomic,retain)NSString *tabOrders;
@end
TabBarVC.m
#import "TabBarVC.h"
#import "testvc1.h"
#import "testvc2.h"
#import "testvc3.h"
#import "testvc4.h"
#import "testvc5.h"
#import "testvc6.h"
#import "testvc7.h"
@interface TabBarVC ()
{
}
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) TabBarVC *tabBarController;
@end
@implementation TabBarVC
- (void)viewDidLoad {
self.tabOrders = @"HOME|home,LOVE|love|,MATCH|match|";
self.tabOrders=[self.tabOrders stringByAppendingString:@",OpenFB|www.facebook.com,OpenWeb|www.google.com,web|www.google.com,YAHOO|www.yahoo.com,GOOGLE|www.google.com"];
//====================================================================================
//========================= View controller used to be assign ========================
//====================================================================================
NSMutableArray *tabViewControllers = [[NSMutableArray alloc] init];
NSMutableArray *resttabViewControllers = [[NSMutableArray alloc] init];
NSMutableArray *tabOrderArray=[[self.tabOrders componentsSeparatedByString:@","] mutableCopy];
for (int i=0; i<[tabOrderArray count]; i++)
{
NSArray *arr_tab=[[tabOrderArray objectAtIndex:i] componentsSeparatedByString:@"|"];
NSString *tabName=[arr_tab objectAtIndex:0]; //get array name from pipe serate
NSString *tabAction=[arr_tab objectAtIndex:1];
if ([tabAction isEqualToString:@"home"])
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
testvc1 *testvc1 = [storyboard instantiateViewControllerWithIdentifier:@"testvc1"];
testvc1.title = @"testvc1";
testvc1.tabBarItem.image=[UIImage imageNamed:@"homeicon"];
UINavigationController *testvc1NavVC = [[UINavigationController alloc] initWithRootViewController: testvc1];
[tabViewControllers addObject:testvc1NavVC];
}
else if ([tabAction isEqualToString:@"love"])
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
testvc2 *testvc2 = [storyboard instantiateViewControllerWithIdentifier:@"testvc2"];
testvc2.title =@"Love";
testvc2.tabBarItem.image=[UIImage imageNamed:@"loveicon"];
UINavigationController *testvc2NavVC = [[UINavigationController alloc] initWithRootViewController: testvc2];
[tabViewControllers addObject:testvc2NavVC];
}
else if ([tabAction isEqualToString:@"match"])
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
testvc3 *testvc3 = [storyboard instantiateViewControllerWithIdentifier:@"testvc3"];
testvc3.title = @"MATCH";
testvc3.tabBarItem.image=[UIImage imageNamed:@"matchicon"];
UINavigationController *testvc3NavVC = [[UINavigationController alloc] initWithRootViewController: testvc3];
[tabViewControllers addObject:testvc3NavVC];
}
else
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
testvc4 *testvc4 = [storyboard instantiateViewControllerWithIdentifier:@"testvc4"];
testvc4.title = tabName; //TabTitle
testvc4.tabBarItem.image=[UIImage imageNamed:@"icon_rest"];
UINavigationController *testvc4NavVC = [[UINavigationController alloc] initWithRootViewController:testvc4];
[resttabViewControllers addObject:testvc4NavVC];
}
}
for (int i=0; i<[resttabViewControllers count]; i++) {
[tabViewControllers addObject:[resttabViewControllers objectAtIndex:i]];
}
[[UINavigationBar appearance] setBarTintColor:[UIColor colorWithRed:15/255.0 green:68/255.0 blue:140/255.0 alpha:1.0]];
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:15/255.0 green:68/255.0 blue:140/255.0 alpha:1.0];
self.navigationController.navigationBar.alpha = 0.7f;
self.navigationController.navigationBar.translucent = YES;
UINavigationController* morenav = self.tabBarController.moreNavigationController;
morenav.navigationBar.tintColor = [UIColor whiteColor];;
morenav.navigationBar.barTintColor=[UIColor colorWithRed:15/255.0 green:68/255.0 blue:140/255.0 alpha:1.0];
[self.navigationController.navigationBar setTitleTextAttributes:
@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
[self.navigationController.navigationBar setTitleTextAttributes:
@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
[self.tabBarController.tabBar setBarTintColor:[UIColor colorWithRed:248/255.0 green:248/255.0 blue:248/255.0 alpha:1.0]];
[self setViewControllers:tabViewControllers];
self.customizableViewControllers = nil;
[self setSelectedIndex:0];
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
打开标签栏我打电话
-(IBAction)openTab:(id)sender
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UITabBarController *tbc = [storyboard instantiateViewControllerWithIdentifier:@"TabBarController"];
[self presentViewController:tbc animated:NO completion:nil];
}
我的故事板下面是uiview控制器,彼此之间没有segue连接。
1) UITabBarController (with class name tabbar and with identifier UITabBarController)
2) UIViewcontrollers
testview1,testview2,testview3,testview4,testview5,testview6,testview7