0

我在 iPad 上添加了带有 4 个选项卡的 UITabbarcontroller 。但是在 Ipad 中,选项卡不是从 x=0 开始的,它是从中间开始的。

我们如何将 Uitabbar 设置为使用 ipad 的全宽(768),以便所有 4 个选项卡都适合全屏宽度

-(void) CreateTabBar
{
    NSString *nibFile =@"";
    NSString *imageType =@"";
   if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
       nibFile = @"_iPhone";
       imageType = @"";
   }
   else{
       nibFile = @"_iPad";
       imageType = @"_iPad";
   }  

   SCViewController *bookCabView = [[SCViewController alloc] init];
   UINavigationController *bookCabNavView = [[UINavigationController alloc]initWithRootViewController:bookCabView];
   bookCabNavView.tabBarItem.image = [UIImage imageNamed:@"bookacab.png"];

  // NSString *orderViewnibFile = @"";
   NSString *serviceViewnibFile = @"";
   NSString *contactusViewnibFile = @"";
   if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
       //orderViewnibFile = @"EXTableViewController_iPhone";
       serviceViewnibFile = @"ServiceViewController_iPhone";
       contactusViewnibFile = @"ContactUsViewController_iPhone";
   }
   else{
       // orderViewnibFile = @"EXTableViewController_iPad";
       serviceViewnibFile = @"ServiceViewController_iPad";
       contactusViewnibFile = @"ContactUsViewController_iPad";
   }
   EXTableViewController *orderView = [[EXTableViewController alloc] init];
   UINavigationController *orderCabNavView = [[UINavigationController alloc]initWithRootViewController:orderView];
   orderCabNavView.tabBarItem.image = [UIImage imageNamed:[@"orders" stringByAppendingFormat:@"%@.png",imageType]];

   ServiceViewController *serviceView = [[ServiceViewController alloc] initWithNibName:serviceViewnibFile bundle:nil];
  UINavigationController *serviceNavView = [[UINavigationController alloc]initWithRootViewController:serviceView];
  serviceNavView.tabBarItem.image = [UIImage imageNamed:[@"services" stringByAppendingFormat:@"%@.png",imageType]] ;
  ContactUsViewController *contactusView = [[ContactUsViewController alloc] initWithNibName:contactusViewnibFile bundle:nil];
  UINavigationController *contactNavView = [[UINavigationController alloc]initWithRootViewController:contactusView];
  contactNavView.tabBarItem.image = [UIImage imageNamed:[@"contactus" stringByAppendingFormat:@"%@.png",imageType]];

  UITabBarItem *tab1 = [[UITabBarItem alloc] initWithTitle:@"" image:[UIImage imageNamed:@""] tag:1];
  tab1.imageInsets = UIEdgeInsetsMake(0, 0, -15, 0);
  [bookCabNavView setTabBarItem:tab1];

  UITabBarItem *tab2 = [[UITabBarItem alloc] initWithTitle:@"" image:[UIImage imageNamed:@""] tag:2];
  tab2.imageInsets = UIEdgeInsetsMake(0, 0, -15, 0);
  [orderCabNavView setTabBarItem:tab2];

  UITabBarItem *tab3 = [[UITabBarItem alloc] initWithTitle:@"" image:[UIImage imageNamed:@""] tag:3];

  tab3.imageInsets = UIEdgeInsetsMake(0, 0, -15, 0);
  [serviceNavView setTabBarItem:tab3];

  UITabBarItem *tab4 = [[UITabBarItem alloc] initWithTitle:@"" image:[UIImage imageNamed:@""] tag:4];

  tab4.imageInsets = UIEdgeInsetsMake(0, 0, -15,0);
 [contactNavView setTabBarItem:tab4];

 _tabBarCon = [[UITabBarController alloc] initWithNibName:nil bundle:nil];

 NSLog(@"%@",[@"bookacabhover" stringByAppendingFormat:@"%@.png",imageType]);

 [tab1 setFinishedSelectedImage:[UIImage imageNamed:[@"bookacabhover" stringByAppendingFormat:@"%@.png",imageType]] withFinishedUnselectedImage:[UIImage imageNamed:[@"bookacab" stringByAppendingFormat:@"%@.png",imageType]]];
 [tab2 setFinishedSelectedImage:[UIImage imageNamed:[@"ordershover" stringByAppendingFormat:@"%@.png",imageType]]withFinishedUnselectedImage:[UIImage imageNamed:[@"orders" stringByAppendingFormat:@"%@.png",imageType]]];
 [tab3 setFinishedSelectedImage:[UIImage imageNamed:[@"serviceshover" stringByAppendingFormat:@"%@.png",imageType ]] withFinishedUnselectedImage:[UIImage imageNamed:[@"services" stringByAppendingFormat:@"%@.png",imageType ]]];
 [tab4 setFinishedSelectedImage:[UIImage imageNamed:[@"contactsushover" stringByAppendingFormat:@"%@.png",imageType]] withFinishedUnselectedImage:[UIImage imageNamed:[@"contactus" stringByAppendingFormat:@"%@.png",imageType ]]];

   _tabBarCon.viewControllers = [NSArray arrayWithObjects:bookCabNavView,
                                    orderCabNavView,
                                    serviceNavView,
                                    contactNavView, nil];
   _tabBarCon.delegate = self;
   [self.view addSubview:_tabBarCon.view];
} 
4

0 回答 0