2013-06-25 197 views
0

我正在嘗試將image添加到UITabbar。目前它有一個黑色的默認閃耀。我想要一個像下面一樣的純色。我怎樣才能將這個添加到xib中的UITabbar如何將圖像添加到UITabbar?

enter image description here

回答

1

試試這個

UIImage* tabBarBackground = [UIImage imageNamed:@"tabbar.png"]; 
    [[UITabBar appearance] setBackgroundImage:tabBarBackground]; 
    [[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:@"tabbar_selected.png"]]; 

Here is a better read on tabbar customization

+0

我會盡量回來到u今天本身由於 – Navi

+0

閱讀的鏈接也將幫助你很多 –

+0

感謝,這是爲我工作 – Navi

0

要自定義中的UITabBar一樣,iOS 5中提供了一個API,讓你改變的TabBar的背景圖像。

// ios 5 code here 

UIImage *tabBackground = [[UIImage imageNamed:@"tab_bg"] 
    resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)]; 
[[UITabBar appearance] setBackgroundImage:tabBackground]; 
[[UITabBar appearance] setSelectionIndicatorImage: 
     [UIImage imageNamed:@"tab_select_indicator"]]; 

// ios 4 code here 

CGRect frame = CGRectMake(0, 0, 480, 49); 
UIView *tabbg_view = [[UIView alloc] initWithFrame:frame]; 
UIImage *tabbag_image = [UIImage imageNamed:@"PB_MD_footer_navBg_v2.png"]; 
UIColor *tabbg_color = [[UIColor alloc] initWithPatternImage:tabbag_image]; 
tabbg_view.backgroundColor = tabbg_color; 
[tabBar insertSubview:tabbg_view atIndex:0]; 

感謝,

0
viewTab1controller = [[ViewTab1Controller alloc] initWithNibName:@"ViewTab1" bundle:nil]; 
viewTab1controller.title = @"Schedules"; 
navigationTab1Controller = [[[UINavigationController alloc] initWithRootViewController:viewTab1controller] autorelease]; 
navigationTab1Controller.tabBarItem.image = [[UIImage imageNamed:@"Match.png"] autorelease]; 
[viewTab1controller release];