简体   繁体   English

标签栏项目图像不会随着情节提要的使用而改变

[英]tab bar item image is not change with use of storyboard

in my application i have to use tab bar.but the problem is my first view is homeviewcontroller and it contain no tab bar or tab bar controller.now when click on login it goes to first view controller and it contain tab bar. 在我的应用程序中,我必须使用标签栏。但是问题是我的第一个视图是homeviewcontroller,它不包含任何标签栏或标签栏控制器。现在单击登录时,它会转到第一个视图控制器,并且它包含标签栏。

i am using story board and when i drag drop tab bar item into navigation controller tab bar item image is not showing i am new to storyboard. 我正在使用情节提要,并且当我将下拉选项卡栏项拖到导航控制器的选项卡栏项中时,图像未显示我是情节提要的新手。 when i am running my app it goes to first view controller but tabbar item not change. 当我运行我的应用程序时,它会转到第一个视图控制器,但选项卡项不会更改。

Here is my code: 这是我的代码:

in homeviewcontroller.m 在homeviewcontroller.m中

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([[segue identifier] isEqualToString:@"sign"])
    { 
     [((AppDelegate *)[[UIApplication sharedApplication]delegate]) configure];  
     NSLog(@"ok");            
    }
}

in appdelegate.m 在appdelegate.m中

-(void)configure
{
    NSLog(@"Call Tabbarcontroller");

   _tabBarController = (UITabBarController *)self.window.rootViewController;

    UIViewController* vc = [_tabBarController.viewControllers objectAtIndex: 0];
    vc.tabBarItem = [[UITabBarItem alloc] initWithTitle: @"title" image:[UIImage imageNamed:@"home.png"] tag:0];

}

//this code for when you select tabbar item tab. //此代码用于选择标签栏项目标签时的代码。

vc.tabBarItem1.selectedImage = [[UIImage imageNamed:@"selectimg"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ];

//this code for default image of tabar item tab. //此代码为Tabar项目标签的默认图片。

 vc.tabBarItem.image = [[UIImage imageNamed:@"deselectimg"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ];

//this code for title of your tabar item tab. //此代码用于Tabar项目标签的标题。

vc.tabBarItem.title = @"xxxx";

使用此代码在选择和取消选择中设置图像,

[tabBarItem1 setFinishedSelectedImage:[UIImage imageNamed:@"homeSelect.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"homeUnSelect.png"]];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM