0

アイテムを選択および選択解除した後に取得する、TabBarItemのデフォルトの効果を変更したい。この方法を使用して、ios5以降のバージョンでこの問題を解決しました

    [mySchedule setFinishedSelectedImage:[UIImage imageNamed:@"myschedule.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"aboutus.png"]]; 

しかし、バージョン 4 以下では問題が発生します。バージョン 4 以下でこの問題をどのように解決したか教えてください。

4

2 に答える 2

1

ここでは、4 つのボタンを持つカスタム タブ バーを作成しました。ボタンは画像で構成され、定数ファイルに取り込まれました。ここで、serviceImg、contactImg などは、.h ファイルで宣言されている UIImageView です。また、UITabBarControllerDelegate をデリゲートとして .h ファイルに追加することを忘れないでください。

-(void)setUpTabBar {

tabBar = [[UITabBarController alloc] init];

Services *firstViewController = [[Services alloc]init];
firstViewController.tabBarItem = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemFavorites tag:1];
UINavigationController *firstNavController = [[UINavigationController alloc]initWithRootViewController:firstViewController];

ContactUs *secondViewController = [[ContactUs alloc]init];
secondViewController.tabBarItem = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemFavorites tag:2];
UINavigationController *secondNavController = [[UINavigationController alloc]initWithRootViewController:secondViewController];

Bookings *thirdViewController = [[Bookings alloc]init];
thirdViewController.tabBarItem = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemFavorites tag:3];
UINavigationController *thirdNavController = [[UINavigationController alloc]initWithRootViewController:thirdViewController];

Reward *fourthViewController = [[Reward alloc]init];
fourthViewController.tabBarItem = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemRecents tag:4];
UINavigationController *fourthNavController = [[UINavigationController alloc]initWithRootViewController:fourthViewController];

tabBar.viewControllers = [[NSArray alloc] initWithObjects:firstNavController, secondNavController, thirdNavController, fourthNavController, nil];
tabBar.delegate=self;
tabBar.selectedIndex=0;

[firstNavController release];
[firstViewController release];

[secondNavController release];
[secondViewController release];

[thirdNavController release];
[thirdViewController release];

[fourthNavController release];
[fourthViewController release];

serivceImg=[[UIImageView alloc]initWithFrame:CGRectMake(0, 432, 80, 49)];
serivceImg.image=[UIImage imageNamed:serviceHover];

contactImg=[[UIImageView alloc]initWithFrame:CGRectMake(81, 432,80, 49)];
contactImg.image=[UIImage imageNamed:tabContact];

bookingImg=[[UIImageView alloc]initWithFrame:CGRectMake(162, 432,80, 49)];
bookingImg.image=[UIImage imageNamed:tabBooking];

rewardImg=[[UIImageView alloc]initWithFrame:CGRectMake(243, 432, 80, 49)];
rewardImg.image=[UIImage imageNamed:tabReward];

[tabBar.view addSubview:serivceImg];
[tabBar.view addSubview:contactImg];
[tabBar.view addSubview:bookingImg];
[tabBar.view addSubview:rewardImg];

[[[UIApplication sharedApplication]keyWindow]addSubview:tabBar.view];

[serivceImg release];
[contactImg release];
[bookingImg release];
[rewardImg release];

}

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController1{

     if (viewController1 == [tabBar.viewControllers objectAtIndex:0])

 {

     serivceImg.image = [UIImage imageNamed:kserviceHover];
     contactImg.image=[UIImage imageNamed:ktabContact];
     bookingImg.image=[UIImage imageNamed:ktabBooking];
     rewardImg.image=[UIImage imageNamed:ktabReward];


 }

else if (viewController1 == [tabBar.viewControllers objectAtIndex:1])

{

    serivceImg.image = [UIImage imageNamed:ktabService];
    contactImg.image=[UIImage imageNamed:kcontactHover];
    bookingImg.image=[UIImage imageNamed:ktabBooking];
    rewardImg.image=[UIImage imageNamed:ktabReward];

}

else if (viewController1 == [tabBar.viewControllers objectAtIndex:2])

{

    serivceImg.image = [UIImage imageNamed:ktabService];
    contactImg.image=[UIImage imageNamed:ktabContact];
    bookingImg.image=[UIImage imageNamed:kbookingHover];
    rewardImg.image=[UIImage imageNamed:ktabReward];

}

else if (viewController1 == [tabBar.viewControllers objectAtIndex:3])

{

    serivceImg.image = [UIImage imageNamed:ktabService];
    contactImg.image=[UIImage imageNamed:ktabContact];
    bookingImg.image=[UIImage imageNamed:ktabBooking];
    rewardImg.image=[UIImage imageNamed:krewardHover];

}

}

これで問題が解決することを願っています。

于 2012-05-01T10:03:30.050 に答える
0

イメージ名から .png を削除します。

于 2012-04-30T11:02:28.683 に答える