问题描述
我在 ios
应用程序中工作我需要自定义 tabbar
,就像
i'm working in ios
application i need to customize tabbar
to be like this
首先我创建了5 viewcontrollers
导航控制器中的每一个
然后将它们放入 tabbbarcontroller
First I created 5 viewcontrollers
each one in navigation controllerthen put them in tabbbarcontroller
我google对于这个问题,我找到了解决方案
I googled for this problem and I found solution
[self.tabBarItem setFinishedSelectedImage:<#(UIImage *)#> withFinishedUnselectedImage:<#(UIImage *)#>]
但它适用于iOS 5,I需要iOS 4和iOS 5的解决方案。
but it is for iOS 5, I need solution for both iOS 4 and iOS 5.
推荐答案
对于自定义ios4中的标签栏,无法提供您需要的代码为了让我们自定义标签栏你可以参考这个Que。
For customizing tab bar in ios4 is not available with code for that you need to make us custom tab bar for that you can refer this Que.
或者您也可以像制作完整的标签栏图像一样简单的逻辑
or you also can do like simple logic with making full tab bar image like this
这里我做了一个图像视图appdel确实完成了方法并在应用程序中这样完成。
here i have made one image view on appdel did finish method and done like this in the app.
self.imgV.frame=CGRectMake(0, 431, 320, 49);
[self.tabbarcontroller.view addSubview:self.imgV];
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController{
NSUInteger index=[[tabBarController viewControllers] indexOfObject:viewController];
NSString *deviceType = [UIDevice currentDevice].model;
NSLog(@"Device%@",deviceType);
if(UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPad){
// self.imgV.frame=CGRectMake(0, 975, 768, 49);
//[self.tabbarcontroller.view addSubview:self.imgV];
switch (index) {
case 0:
self.imgV.image=[UIImage imageNamed:@"reservation_tab~iPad.png"];
break;
case 1:
self.imgV.image=[UIImage imageNamed:@"place_order_tab~iPad.png"];
break;
case 2:
self.imgV.image=[UIImage imageNamed:@"location_tab~iPad.png"];
break;
case 3:
self.imgV.image=[UIImage imageNamed:@"favorite_tab~iPad.png"];
break;
case 4:
self.imgV.image=[UIImage imageNamed:@"signature_dishes_tab~iPad.png"];
break;
case 5:
self.imgV.image=[UIImage imageNamed:@"history_tab~iPad.png"];
break;
case 6:
self.imgV.image=[UIImage imageNamed:@"contact_us_tab~iPad.png"];
break;
default:
break;
}
}
else{
switch (index) {
case 0:
self.imgV.image=[UIImage imageNamed:@"reservation_tab.png"];
break;
case 1:
self.imgV.image=[UIImage imageNamed:@"place_order_tab.png"];
break;
case 2:
self.imgV.image=[UIImage imageNamed:@"location_tab.png"];
break;
case 3:
self.imgV.image=[UIImage imageNamed:@"favorite_tab.png"];
break;
case 4:
self.imgV.image=[UIImage imageNamed:@"gallery_tab.png"];
break;
default:
break;
}
}
return YES;
}
这篇关于ios tabbar自定义图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!