自定义标签栏大小

时间:2012-09-27 12:07:22

标签: objective-c ios5 uitabbar

我正在制作一个自定义标签栏,我添加了一个320x82的背景图片,每个标签我都有一个高度为82的选择图片。 问题是当标签栏框架与背景高度(82)匹配时,它会得到一种不在原始布局上的阴影,并且选择图像不对齐。我在这里如何设置标签栏:

    self.tabBatController = [[UITabBarController alloc] init];
    self.tabBarController.viewControllers = [NSArray arrayWithObjects:myView1, myView2, myView3, nil];

    UIImage *tabBackground = [[UIImage imageNamed:@"tab_bar_background"] resizableImageWithCapInsets:UIEdgeInsetsMake(0,0,0,0)];
    [[UITabBar appearence] setBackgroundImage:tabBackground];

    UITabBar *tabBar = self.tabBarController.tabBar;

    CGRect viewFrame = tabBar.frame;
    viewFrame.origin.y -=41; //the correct position of the tab bar
    viewFrame.size.height = 82; //the correct height
    tabBar.frame = viewFrame;

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

//this set of images are not aligned with the tabs
    [item1 setFinishedSelectedImage:[UIImage imageNamed:@"tab1_selected"] withFinishedUnselectedImage:[UIImage imageNamed:@"tab1_unselected"]];

    [item2 setFinishedSelectedImage:[UIImage imageNamed:@"tab2_selected"] withFinishedUnselectedImage:[UIImage imageNamed:@"tab2_unselected"]];

    [item3 setFinishedSelectedImage:[UIImage imageNamed:@"tab3_selected"] withFinishedUnselectedImage:[UIImage imageNamed:@"tab3_unselected"]];

选项卡的大小正确,但它具有此阴影和未对齐的选择图像。我该如何纠正?

0 个答案:

没有答案