1

我正在制作一个自定义标签栏,我添加了一个 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"]];

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

4

0 回答 0