UITabBarItem是否可以没有图像,但是文本更大?

时间:2010-06-21 18:43:07

标签: iphone cocoa-touch uikit interface-builder

是否可以让UITabBarItem没有图像,但是文字更大呢?

例如:要有全高的文字吗?

3 个答案:

答案 0 :(得分:4)

当然,只需制作较大文字的图像即可。据我所知,这是唯一的方法。

答案 1 :(得分:1)

是的,您可以使用如下的空图像对其进行初始化:

 UIImage* image = [[UIImage alloc] init];
 tabBarItem = [[UITabBarItem alloc] initWithTitle:title image:image tag:tag] ;
 [image release];

仅显示标题文字。

答案 2 :(得分:0)

完全解决方案就在这里。

您需要将空图像设置为tabBarItem。否则tabBarItem在您点击之前不会出现。

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

    if (self) {

        self.tabBarItem.title = @"Report";
        self.tabBarItem.image = [[UIImage alloc] init];

    }

    return self;
}

UITabBar的自定义:

- (void)customizeAppearance
{
    [[UITabBar appearance] setBarTintColor:[UIColor blackColor]];
    [[UITabBar appearance] setTranslucent:NO];
    [[UITabBarItem appearance] setTitleTextAttributes:@{ NSForegroundColorAttributeName:[UIColor whiteColor],
                                                         NSFontAttributeName: [UIFont fontWithName:@"HelveticaNeue-Thin" size:22]}
                                             forState:UIControlStateNormal];

    [[UITabBarItem appearance] setTitleTextAttributes:@{ NSForegroundColorAttributeName:RGB(0xff9700),
                                                         NSFontAttributeName: [UIFont fontWithName:@"HelveticaNeue-Thin" size:22]}
                                             forState:UIControlStateSelected];

    [[UITabBarItem appearance] setTitlePositionAdjustment:UIOffsetMake(0.0, -10.0)];
}