如何改变UITabBarItem的位置?

时间:2013-07-18 17:27:34

标签: uitabbarcontroller uitabbar uitabbaritem

我需要在突出显示时更改UITabBarItem的图像和文本位置。有可能吗?

1 个答案:

答案 0 :(得分:1)

看起来没有办法改变UITabBarItem图像的位置。我刚刚修改了我选中的图像,按钮中有大约15个像素,并在tabBar中修正了UITabBarItem标题的位置:didSelectItem:我自定义UITabBarController的方法:

- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
{
    // If there is another selected item set default properties to it.
    for (int counter = 0; counter < [self.tabBar.items count]; counter++) {
        UITabBarItem *currentSelectedItem = [self.tabBar.items objectAtIndex:counter];
        [currentSelectedItem setTitlePositionAdjustment:UIOffsetMake(0, 0)];
    }

    // Set selected item.
    UITabBarItem *selectedItem = item;
    [selectedItem setTitlePositionAdjustment:UIOffsetMake(0, -15)];
}