100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > 设置uitabBar中某个item只显示图片不显示文字 并且图片垂直居中

设置uitabBar中某个item只显示图片不显示文字 并且图片垂直居中

时间:2019-07-11 10:51:18

相关推荐

设置uitabBar中某个item只显示图片不显示文字 并且图片垂直居中

ios 开发中,如何设置 uitabbar 里面 tabbaritem 不显示文字,只显示图片,图片垂直居中?

-(void)creatTabbar{DisCoverViewController *webVC = [[DisCoverViewController alloc]initWithUrl:[NSString stringWithFormat:@"/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);}}}}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。