I have a UITabBarItem like so:
_Controller.tabBarItem = [[UITabBarItem alloc] initWithTitle:nil image:nil tag:0];
But having nil for a title removes the label needed for accessibility and KIF testing. An alternative I found is to set the title and move it off the screen, but that seems like a hacky solution:
_Controller.tabBarItem.title = @"Foo";
_Controller.tabBarItem.titlePositionAdjustment = UIOffsetMake(0, 200);
Is it possible to have a UITabBarItem without a title, but still have an accessibility label?
EDIT to add full code for tab bar and background button code:
- (void) loadViewController {
_Controller = [[UIViewController alloc] init];
UIImage *normalImage = [UIImage imageNamed:@"bar.png"];
UIImage *selectedTabImage = [UIImage imageNamed:@"barHover.png"];
[self addCenterButtonWithImage:normalImage
highlightImage:selectedTabImage];
_Controller.tabBarItem = [[UITabBarItem alloc] initWithTitle:nil image:nil tag:0];
}
// Create a custom UIButton and add it to the center of our tab bar
-(void) addCenterButtonWithImage:(UIImage*)buttonImage highlightImage:(UIImage*)highlightImage
{
UIButton* button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(0.0, 0.0, buttonImage.size.width, buttonImage.size.height);
[button setBackgroundImage:buttonImage forState:UIControlStateNormal];
[button setBackgroundImage:highlightImage forState:UIControlStateHighlighted];
[button addTarget:self action:@selector(openCamera) forControlEvents:UIControlEventTouchUpInside];
button.center = CGPointMake(self.tabBar.frame.size.width/2.0, self.tabBar.frame.size.height/2.0 - 6.0);
[self.tabBar addSubview:button];
}