0

我正在尝试将一个添加image到一个UITabbar. 目前它具有默认光泽的黑色。我想要一个像下面这样的纯色。如何将其添加到UITabbarxib 中?

在此处输入图像描述

4

3 回答 3

1

试试这个

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

这是关于标签栏自定义的更好读物

于 2013-06-25T12:26:36.830 回答
0

为了自定义 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];

谢谢,

于 2013-06-25T12:26:51.410 回答
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];
于 2013-06-25T12:37:51.903 回答