如何更改所选标签栏图标的笔划

时间:2012-06-16 12:15:01

标签: iphone objective-c uitabbarcontroller uitabbar stroke

我试图找出如何更改所选标签栏图标的笔划。它的青色就像所选图标的色调一样。我已经更改了所选图标的色调和指示图像:self.tabBarController.tabBar.selectedImageTintColor = [UIColor grayColor]; self.tabBarController.tabBar.selectionIndicatorImage = [UIImage imageNamed:@"selectedTab.png"];

但是现在我仍然围绕图标

获得了这个青色笔触

Image

有没有人知道代码,因为我找不到它

2 个答案:

答案 0 :(得分:3)

我之前也注意到了这一点。我最终只是手动设置选定和未选择的图像,而不是让它为我渲染颜色。

然后,您可以使用Photoshop或您喜欢的图像编辑软件为每个标签设计两个图像。选择选项卡时,一个图像将成为选项卡图标,未选中选项卡时,其他图像将用于选项卡。您需要在Photoshop中自己应用色调颜色。

将所有图像导入Xcode后,您可以在所需的UITabBarItem上设置它们。我通常在我的View Controllers init函数中设置它们。

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        [self.tabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"my-selected-icon"] withFinishedUnselectedImage:[UIImage imageNamed:@"my-deselected-icon"]];
    }
    return self;
}

您必须为标签栏上的每个视图控制器执行此操作。

答案 1 :(得分:1)

尝试使用此代码,将其放在viewDidLoad:

for (UITabBarItem * barItem in theTabBar.items) {
    UIImage * image = barItem.image;
    [barItem setFinishedSelectedImage:image withFinishedUnselectedImage:image];
}
相关问题