2015-11-02 39 views
0

我正在UITabbarview控制器上工作,我用下面的代码设置了一个图像,但是在第一次打开视图时它不可见。如何在UITabbaritem上设置图像?

UIImage *prfimage = [UIImage imageNamed:@"profile_o.png"]; UITabBarItem *tbP = [[UITabBarItem alloc] initWithTitle:@""  image:prfimage tag:YES]; 
[self setTabBarItem:tbP]; 
[[UITabBar appearance] setTintColor:[UIColor colorWithRed:247/255.0f green:148/255.0f blue:29/255.0f alpha:2.0f]]; 
self.tabBarItem.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0); 
self.title = nil; 

回答

0

,您应该使用的代码,这个和平设置UIImage的ViewController

[[[[self.tabBarController tabBar] items] objectAtIndex:0] setImage:[[UIImage imageNamed:@"yourImage"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]] ;//objectAtIndex:0 mean your first TabBar item You can do it for multiple. 

它将help.Thanks

+0

先生您好,它在我的情况下不能正常工作,出现图像时我点击它的位置,如果我再次点击比图像变焦 –