iPad に 4 つのタブを持つ UITabbarcontroller を追加しました。しかし、iPadでは、タブはx = 0の中央から始まっていません。
4 つのタブすべてが全画面幅に収まるように、Uitabbar を ipad の全幅 (768) を使用するように設定する方法
-(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];
}