您必须为所有 3 个选项卡创建 2 个图像,其中一个未选中,第二个已选中。
之后在您的 appdelegate.m 文件中写入以下代码
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
self.searchArray = [[NSMutableArray alloc]init];
self.tabBarController = [[[UITabBarController alloc] init] autorelease];
viewController1 *view1 = [[[viewController1 alloc] initWithNibName:@"viewController1" bundle:nil] autorelease];
view1.tabBarItem.image = [UIImage imageNamed:@"tab-selected-1"];
view1.tabBarItem.title = @"Title1";
viewController2 *view2 = [[[viewController2 alloc] initWithNibName:@"viewController2" bundle:nil] autorelease];
view2.tabBarItem.image = [UIImage imageNamed:@"tab-selected-2"];
view2.tabBarItem.title = @"Title2";
viewController3 *view3 = [[[viewController3 alloc] initWithNibName:@"viewController3" bundle:nil] autorelease];
view3.tabBarItem.image = [UIImage imageNamed:@"tab-selected-3"];
view3.tabBarItem.title = @"Title3";
self.tabBarController.viewControllers = [NSArray arrayWithObjects:view1, view2, view3, nil];
UITabBarItem *tabBarItem1 = [[self.tabBarController.tabBar items] objectAtIndex:0];
[tabBarItem1 setFinishedSelectedImage:[UIImage imageNamed:@"tab-selected-1.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"tab-unselected-1.png"]];
UITabBarItem *tabBarItem2 = [[self.tabBarController.tabBar items] objectAtIndex:1];
[tabBarItem2 setFinishedSelectedImage:[UIImage imageNamed:@"tab-selected-2.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"tab-unselected-2.png"]];
UITabBarItem *tabBarItem3 = [[self.tabBarController.tabBar items] objectAtIndex:2];
[tabBarItem3 setFinishedSelectedImage:[UIImage imageNamed:@"tab-selected-3.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"tab-unselected-3.png"]];
return YES;
}
试试这个,你的问题就解决了。祝你好运