Ios 如何将图像添加到UITabbar?

Ios 如何将图像添加到UITabbar?,ios,objective-c,uiimage,uitabbar,Ios,Objective C,Uiimage,Uitabbar,我正在尝试将图像添加到uitabar。目前它有一个默认的光泽黑色。我想要下面这样的纯色。如何将其添加到xib中的uitabar 试试这个 UIImage* tabBarBackground = [UIImage imageNamed:@"tabbar.png"]; [[UITabBar appearance] setBackgroundImage:tabBarBackground]; [[UITabBar appearance] setSelectionIndicator

我正在尝试将
图像添加到
uitabar
。目前它有一个默认的光泽黑色。我想要下面这样的纯色。如何将其添加到xib中的
uitabar

试试这个

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

要自定义UITabBar,iOS 5提供了一个API,允许您更改选项卡栏的背景图像

// 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];

谢谢,

也请阅读该链接,它将对您有很大帮助
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];