我将一页转到另一页,而另一页具有UITabbarcontroller
。
具有:
现在显示了这五个名称,但是我没有显示这五个图标图像,并且屏幕显示黑色,如果我执行clearcolor,则屏幕显示灰色。
我还想要如何控制
UITabbarcontroller
的高度。我的问题是图标图像未显示在选项卡上。
我还在UITabbar上添加背景图像,还添加了图标图像。但是它没有显示。
这是我的代码。
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
// Retrieve the last view name
NSInteger firstValue = [[NSUserDefaults standardUserDefaults] integerForKey:@"firstValue"];
if (firstValue == 10) {
[self method_Tabs];
}
}
-(void)method_Tabs{
// Set the name of the view
[[NSUserDefaults standardUserDefaults] setInteger:11 forKey:@"firstValue"];
my_Tabbar = [[UITabBarController alloc] init]; // how to control height of my_Tabbar?
// my_Tabbar.view.frame=CGRectMake(0, 100, 320,30); // is there any way to control this
// my_Tabbar.view.backgroundColor = [UIColor redColor];
my_Tabbar.tabBar.barTintColor = [UIColor clearColor];
self.tabBarController.tabBar.translucent = false;
// this will give selected icons and text your apps tint color
my_Tabbar.tabBar.tintColor = [UIColor blueColor];
[[UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName : [UIFont fontWithName:@"HelveticaNeue-Bold" size:13.0f],
NSForegroundColorAttributeName : [UIColor colorWithRed:.5 green:.5 blue:.5 alpha:1]
} forState:UIControlStateNormal];
Homepage_AdvancePipeOffset *VC_1 = [[Homepage_AdvancePipeOffset alloc] initWithNibName:nil bundle:nil];
Apo_Cut_Pipe *VC_2 = [[Apo_Cut_Pipe alloc] initWithNibName:nil bundle:nil];
Apo_Fitting *VC_3 = [[Apo_Fitting alloc] initWithNibName:nil bundle:nil];
Apo_Flange *VC_4 = [[Apo_Flange alloc] initWithNibName:nil bundle:nil];
Apo_Setting *VC_5 = [[Apo_Setting alloc] initWithNibName:nil bundle:nil];
UINavigationController *rvc_Home = [[UINavigationController alloc] initWithRootViewController: VC_1];
UINavigationController *rvc_CutPipe = [[UINavigationController alloc] initWithRootViewController: VC_2];
UINavigationController *rvc_Fitting = [[UINavigationController alloc] initWithRootViewController: VC_3];
UINavigationController *rvc_Flange = [[UINavigationController alloc] initWithRootViewController: VC_4];
UINavigationController *rvc_Setting = [[UINavigationController alloc] initWithRootViewController: VC_5];
rvc_Home.tabBarItem.image =[UIImage imageNamed:@"home.png"];
rvc_CutPipe.tabBarItem.image =[UIImage imageNamed:@"icon_cut_pipe.png"];
rvc_Fitting.tabBarItem.image =[UIImage imageNamed:@"icon_fittings.png"];
rvc_Flange.tabBarItem.image =[UIImage imageNamed:@"icon_flanges.png"];
rvc_Setting.tabBarItem.image =[UIImage imageNamed:@"icon_settings.png"];
rvc_Home.tabBarItem.title=@"Home";
VC_1.tabBarController.tabBar.tag = 1;
rvc_CutPipe.tabBarItem.title=@"CutPipe";
VC_2.tabBarController.tabBar.tag = 2;
rvc_Fitting.tabBarItem.title=@"Fitting";
VC_3.tabBarController.tabBar.tag = 3;
rvc_Flange.tabBarItem.title=@"Flange";
VC_4.tabBarController.tabBar.tag = 4;
rvc_Setting.tabBarItem.title=@"Setting";
VC_5.tabBarController.tabBar.tag = 5;
NSArray* controllers = [NSArray arrayWithObjects: rvc_Home,rvc_CutPipe,rvc_Fitting,rvc_Flange, rvc_Setting, nil];
[my_Tabbar setViewControllers: controllers animated:NO];
[self.view addSubview:my_Tabbar.view];
my_Tabbar.selectedIndex=4;
[self.navigationController pushViewController:my_Tabbar animated:YES];
}
最佳答案
我建议您将UITabBarController
子类化,并在tabBarItem
方法中的viewDidLoad
中设置自定义图像。
检查此代码:
- (void)viewDidLoad
{
[super viewDidLoad];
UITabBar *tabBar = self.tabBar;
UITabBarItem *item0 = [tabBar.items objectAtIndex:0];
UITabBarItem *item1 = [tabBar.items objectAtIndex:1];
UITabBarItem *item2 = [tabBar.items objectAtIndex:2];
UITabBarItem *item3 = [tabBar.items objectAtIndex:3];
[item0 setFinishedSelectedImage:[UIImage imageNamed:@"search-icon"] withFinishedUnselectedImage:[UIImage imageNamed:@"search-icon"]];
[item0 setImageInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
[item1 setFinishedSelectedImage:[UIImage imageNamed:@"tag-icon"] withFinishedUnselectedImage:[UIImage imageNamed:@"tag-icon"]];
[item1 setImageInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
[item2 setFinishedSelectedImage:[UIImage imageNamed:@"add-icon"] withFinishedUnselectedImage:[UIImage imageNamed:@"add-icon"]];
[item2 setImageInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
[item3 setFinishedSelectedImage:[UIImage imageNamed:@"profile-icon"] withFinishedUnselectedImage:[UIImage imageNamed:@"profile-icon"]];
[item3 setImageInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
self.selectedIndex=2;
}
在我看来是这样的:
关于ios - 图标图像未显示在iOS 7的标签栏中?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21986978/