3
我有一個tabbarcontroller被推到navigationController上。我試圖改變標籤欄的背景顏色但是它不工作:iOS TabBarController背景顏色
UIViewController *viewController1, *viewController2;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
viewController1 = [[Tab1_iPhone alloc] initWithNibName:@"tab1_iPhone" bundle:nil];
viewController2 = [[Tab2_iPhone alloc] initWithNibName:@"tab2_iPhone" bundle:nil];
}
self.tabBarController = [[UITabBarController alloc] init];
CGRect frame = CGRectMake(0.0, 0.0, 480, 48);
UIView *v = [[UIView alloc] initWithFrame:frame];
[v setBackgroundColor:[UIColor blueColor]]; //003366
[v setAlpha:1.0];
[[self.tabBarController tabBar] insertSubview:v atIndex:0];
self.tabBarController.viewControllers = [NSArray arrayWithObjects: viewController1, viewController2, nil];
[self.navigationController setNavigationBarHidden:YES];
[self.navigationController pushViewController:self.tabBarController animated:YES];
[self.window makeKeyAndVisible];
這是我上一個類似的職位,改變背景顏色看到代碼:
CGRect frame = CGRectMake(0.0, 0.0, 480, 48);
UIView *v = [[UIView alloc] initWithFrame:frame];
[v setBackgroundColor:[UIColor blueColor]]; //003366
[v setAlpha:1.0];
[[self.tabBarController tabBar] insertSubview:v atIndex:0];
我做有問題?
感謝
嘗試addSubview,而不是insertSubview – craig1231 2012-01-01 23:11:51