2014-02-24 41 views
1

我要去另一頁,另一頁有UITabbarcontroller圖標圖像不顯示在iOS 7的tabbar上?

有:

  1. 首頁2 CutPipe 3件4法蘭5.設置

現在這五個名字都出現了,但我有沒有顯示這五個圖標和圖像屏幕顯示黑色和如果我做clearcolor然後屏幕顯示灰色。

我也想要如何控制高度UITabbarcontroller

我的問題是圖標圖像不顯示在tabbar上。

我還在UITabbar上添加背景圖像,並在圖標圖像上添加。但它沒有顯示。

這是我的代碼。在您的標籤實現以下

rvc_Home.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"Home" image:[[UIImage imageNamed:@"home.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] selectedImage:[UIImage imageNamed:HOME_SELECTED_IMAGE]]; 

編輯

添加代碼:

- (void)viewDidLoad 
{ 
[super viewDidLoad]; 
// Do any additional setup after loading the view. 

// Retrieve the last view name 
NSInteger firstValue = [[NSUserDefaults standardUserDefaults] integerForKey:@"firstValue"]; 

if (firstValue == 10) { 
    [self method_Tabs]; 
} 
} 


-(void)method_Tabs{ 


// Set the name of the view 
[[NSUserDefaults standardUserDefaults] setInteger:11 forKey:@"firstValue"]; 




    my_Tabbar = [[UITabBarController alloc] init]; // how to control height of my_Tabbar? 
// my_Tabbar.view.frame=CGRectMake(0, 100, 320,30); // is there any way to control this 
// my_Tabbar.view.backgroundColor = [UIColor redColor]; 

    my_Tabbar.tabBar.barTintColor = [UIColor clearColor]; 

self.tabBarController.tabBar.translucent = false; 

// this will give selected icons and text your apps tint color 
my_Tabbar.tabBar.tintColor = [UIColor blueColor]; 

[[UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName : [UIFont fontWithName:@"HelveticaNeue-Bold" size:13.0f], 
                NSForegroundColorAttributeName : [UIColor colorWithRed:.5 green:.5 blue:.5 alpha:1] 
                } forState:UIControlStateNormal]; 




Homepage_AdvancePipeOffset *VC_1 = [[Homepage_AdvancePipeOffset alloc] initWithNibName:nil bundle:nil]; 
Apo_Cut_Pipe    *VC_2 = [[Apo_Cut_Pipe alloc] initWithNibName:nil bundle:nil]; 
Apo_Fitting     *VC_3 = [[Apo_Fitting alloc] initWithNibName:nil bundle:nil]; 
Apo_Flange     *VC_4 = [[Apo_Flange alloc] initWithNibName:nil bundle:nil]; 
Apo_Setting     *VC_5 = [[Apo_Setting alloc] initWithNibName:nil bundle:nil]; 




UINavigationController *rvc_Home  = [[UINavigationController alloc] initWithRootViewController: VC_1]; 
UINavigationController *rvc_CutPipe = [[UINavigationController alloc] initWithRootViewController: VC_2]; 
UINavigationController *rvc_Fitting = [[UINavigationController alloc] initWithRootViewController: VC_3]; 
UINavigationController *rvc_Flange = [[UINavigationController alloc] initWithRootViewController: VC_4]; 
UINavigationController *rvc_Setting = [[UINavigationController alloc] initWithRootViewController: VC_5]; 


rvc_Home.tabBarItem.image =[UIImage imageNamed:@"home.png"]; 
rvc_CutPipe.tabBarItem.image =[UIImage imageNamed:@"icon_cut_pipe.png"]; 
rvc_Fitting.tabBarItem.image =[UIImage imageNamed:@"icon_fittings.png"]; 
rvc_Flange.tabBarItem.image =[UIImage imageNamed:@"icon_flanges.png"]; 
rvc_Setting.tabBarItem.image =[UIImage imageNamed:@"icon_settings.png"]; 


[email protected]"Home"; 
VC_1.tabBarController.tabBar.tag = 1; 

[email protected]"CutPipe"; 
VC_2.tabBarController.tabBar.tag = 2; 

[email protected]"Fitting"; 
VC_3.tabBarController.tabBar.tag = 3; 

[email protected]"Flange"; 
VC_4.tabBarController.tabBar.tag = 4; 

[email protected]"Setting"; 
VC_5.tabBarController.tabBar.tag = 5; 


NSArray* controllers = [NSArray arrayWithObjects: rvc_Home,rvc_CutPipe,rvc_Fitting,rvc_Flange, rvc_Setting, nil]; 


[my_Tabbar setViewControllers: controllers animated:NO]; 
[self.view addSubview:my_Tabbar.view]; 
my_Tabbar.selectedIndex=4; 
[self.navigationController pushViewController:my_Tabbar animated:YES]; 

} 
+0

圖像將不會顯示如果太大了。你有沒有嘗試減小圖像的幀大小?如果它適用於小圖標圖像,請嘗試[icon finder](https://www.iconfinder.com/)。 – GoGreen

+0

圖標大小僅爲每張圖片120 * 98 – Tina

+0

請嘗試圖片尺寸小於或等於48 x 32. – GoGreen

回答

3

我會建議你繼承你的UITabBarControllerviewDidLoad方法設置tabBarItem您的自定義圖像。

檢查這個代碼:

- (void)viewDidLoad 
{ 
[super viewDidLoad]; 

UITabBar *tabBar = self.tabBar; 

UITabBarItem *item0 = [tabBar.items objectAtIndex:0]; 
UITabBarItem *item1 = [tabBar.items objectAtIndex:1]; 
UITabBarItem *item2 = [tabBar.items objectAtIndex:2]; 
UITabBarItem *item3 = [tabBar.items objectAtIndex:3]; 

[item0 setFinishedSelectedImage:[UIImage imageNamed:@"search-icon"] withFinishedUnselectedImage:[UIImage imageNamed:@"search-icon"]]; 


[item0 setImageInsets:UIEdgeInsetsMake(0, 0, 0, 0)]; 
[item1 setFinishedSelectedImage:[UIImage imageNamed:@"tag-icon"] withFinishedUnselectedImage:[UIImage imageNamed:@"tag-icon"]]; 
[item1 setImageInsets:UIEdgeInsetsMake(0, 0, 0, 0)]; 
[item2 setFinishedSelectedImage:[UIImage imageNamed:@"add-icon"] withFinishedUnselectedImage:[UIImage imageNamed:@"add-icon"]]; 
[item2 setImageInsets:UIEdgeInsetsMake(0, 0, 0, 0)]; 
[item3 setFinishedSelectedImage:[UIImage imageNamed:@"profile-icon"] withFinishedUnselectedImage:[UIImage imageNamed:@"profile-icon"]]; 
[item3 setImageInsets:UIEdgeInsetsMake(0, 0, 0, 0)]; 

self.selectedIndex=2; 
} 

它看起來像這樣一些事情對我說:

custom tab bar

+0

什麼是您的標籤欄高度和圖標大小(寬度和高度)? – Tina

+0

圖標大小爲1x(80×62像素)和2x(160×124像素) – Pawan

+0

@Tina幫助您與否。 – Pawan

1

試試這個設置標籤欄項目

[[yourTabBarController tabBar] setBackgroundImage:[UIImage imageNamed:@"tabBarBg.png"]]; 
[[yourTabBarController tabBar] setSelectionIndicatorImage:[UIImage imageNamed:@"selectionImage.png"]]; 

[[yourTabBarController tabBar] setTintColor:[UIColor whiteColor]]; 
+0

??? – Tina

+0

您可以使用任何圖像。由於您沒有提供任何選定的圖像,我剛剛命名它。你可以使用你的Home.png –

+0

什麼是HOME_SELECTED_IMAGE? – Tina

0

嘗試使用:

VC_1.tabBarItem.image =[UIImage imageNamed:@"home.png"]; 
VC_2.tabBarItem.image =[UIImage imageNamed:@"icon_cut_pipe.png"]; 
VC_3.tabBarItem.image =[UIImage imageNamed:@"icon_fittings.png"]; 
VC_4.tabBarItem.image =[UIImage imageNamed:@"icon_flanges.png"]; 
VC_5.tabBarItem.image =[UIImage imageNamed:@"icon_settings.png"]; 
0
self.tabBarController = [[UITabBarController alloc] init]; 
    self.tabBarController.delegate = self; 
    self.tabBarController.selectedIndex = 0; 
    UITabBar *tabBar = self.tabBarController.tabBar; 
    UITabBarItem *item0 = [tabBar.items objectAtIndex:0];  
    if(IsRunningTallPhone()) 
     self.tabBarController.tabBar.frame = CGRectMake(0, 430+88, 320, 62); 
    else 
     self.tabBarController.tabBar.frame = CGRectMake(0, 430, 320, 62); 
    UIImage *selectedImageTab0 =[UIImage imageNamed:@"home_btn_selected.png"]; 
    UIImage *unselectedTab0 =[UIImage imageNamed:@"home_btn.png"];  
    [item0 setFinishedSelectedImage:selectedImageTab0 withFinishedUnselectedImage:unselectedTab0]; 
1

嘗試使用

VC_1.tabBarItem=[[UITabBarItem alloc]initWithTitle:@"Home" image:[UIImage imageNamed:@"HomeOn.png"] selectedImage:[UIImage imageNamed:@"HomeOf.png"]]; 

或者

VC_1.tabBarItem=[[UITabBarItem alloc]initWithTitle:@"Home" image:[UIImage imageNamed:@"home"] tag:1]; 
+0

如問iOS 7,這是正確的答案。 –

0

請試試這個

[UITabBarItem setImage:[[UIImage imageNamed:@"tab_03"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]]; 

[UITabBarItem setSelectedImage:[[UIImage imageNamed:@"tab_03_h"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];