是否可以使用没有图片的UITabBarItem,而是用更大的文本替代?
例如:使用全高的文本?
是否可以使用没有图片的UITabBarItem,而是用更大的文本替代?
例如:使用全高的文本?
是的,您可以使用空图像进行初始化,如下所示:
UIImage* image = [[UIImage alloc] init];
tabBarItem = [[UITabBarItem alloc] initWithTitle:title image:image tag:tag] ;
[image release];
只有标题文本将被显示。
完整解决方案在此处。
您需要将空图像设置为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)];
}