ios 开发中,如何设置 uitabbar 里面 tabbaritem 不显示文字,只显示图片,图片垂直居中?
-(void)creatTabbar{
DisCoverViewController *webVC = [[DisCoverViewController alloc]initWithUrl:[NSString stringWithFormat:@"https://h5.axguanjia.com/iosNews.html?isApp=1&userId=%@",[MyHandle shareHandle].ID]];
[self addChildVC:webVC title:@"发现" imageName:@"home_discover_icon_normal" selectImage:@"home_bill_icon_press"];
AiXinGuanJiaLoansQuickBillViewController *billVC = [[AiXinGuanJiaLoansQuickBillViewController alloc]init];
[self addChildVC:billVC title:@"账单" imageName:@"home_bill_icon_normal" selectImage:@"bill_add_btn"];
if (![MyHandle shareHandle].ID.length) {
[MyHandle shareHandle].ID = @"";
}
AiXinGuanJiaLoansQuickMineViewControllerSuperMarketAiXinGuanJia *mineVC = [[AiXinGuanJiaLoansQuickMineViewControllerSuperMarketAiXinGuanJia alloc]init];
[self addChildVC:mineVC title:l10n(@"tabbar_mine_tittle") imageName:@"home_mine_icon_normal" selectImage:@"home_mine_icon_press"];
[self.tabBar setBackgroundImage:[UIImage imageWithColor:typeFaceSCffffff]];
[self.tabBar setShadowImage:[UIImage imageWithColor:kLineColor]];
self.delegate = self;
}
-(void)addChildVC:(UIViewController *)ChildVC title:(NSString *)title imageName:(NSString *)imageName selectImage:(NSString *)selectImage{
ChildVC.tabBarItem.title = title;
ChildVC.tabBarItem.image = [[UIImage imageNamed:imageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
ChildVC.tabBarItem.selectedImage = [[UIImage imageNamed:selectImage] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
AiXinGuanJiaMYNavigationControllerAiXinGuanJia *ChildNVC = [[AiXinGuanJiaMYNavigationControllerAiXinGuanJia alloc]initWithRootViewController:ChildVC];
self.tabBar.tintColor = kNavcBackGroudColor;
ChildNVC.navigationBar.tintColor = kNavcTittleColor;//设置系统自带返回按钮的颜色
self.tabBar.translucent = NO;
ChildVC.navigationItem.title = title;
[[UINavigationBar appearance]
setTitleTextAttributes:@{NSForegroundColorAttributeName:kNavcTittleColor,
NSFontAttributeName:[UIFont systemFontOfSize:18.f]}];
[ChildNVC.navigationBar setBackgroundImage:[UIImage imageWithColor:kTabBarSelectColor] forBarMetrics:UIBarMetricsDefault];
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"//去掉 api 版本问题引起的警告(引号里面是消除警告的类型)
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
#pragma clang diagnostic pop
[self addChildViewController:ChildNVC];
self.selectedIndex = 1;
if (self.selectedIndex == 1) {
CGFloat offset = 8.0;
for (UITabBarItem *item in self.tabBar.items) {
if ([item.title isEqualToString:@"账单"]) {
item.imageInsets = UIEdgeInsetsMake(offset, 0, -offset, 0);
item.titlePositionAdjustment = UIOffsetMake(0, 20);
}
}
}
}
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{
if (tabBarController.selectedIndex != 1) {
for (UITabBarItem *item in self.tabBar.items) {
if ([item.title isEqualToString:@"账单"]) {
item.imageInsets = UIEdgeInsetsMake(0, 0, 0, 0);
item.titlePositionAdjustment = UIOffsetMake(0, 0);
}
}
}else{
CGFloat offset = 8.0;
for (UITabBarItem *item in self.tabBar.items) {
if ([item.title isEqualToString:@"账单"]) {
item.imageInsets = UIEdgeInsetsMake(offset, 0, -offset, 0);
item.titlePositionAdjustment = UIOffsetMake(0, 20);
}
}
}
}