storyboard tabbarcontroller设置tab的图片

时间:2022-02-02 18:11:06

在storyboard里逐项设置了图片,咦,怎么是颜色?别急,慢慢来

找到你的tabbarcontroller指向的viewcontroller,在viewdidload里做如下事,搞定

 - (void)viewDidLoad {
[super viewDidLoad]; UITabBar *tabBar = self.tabBar; UIView *backView = [[UIView alloc] initWithFrame:CGRectMake(, , tabBar.frame.size.width, tabBar.frame.size.height)];
backView.backgroundColor = [UIColor whiteColor];
[tabBar insertSubview:backView atIndex:]; UITabBarItem *item0 = [tabBar.items objectAtIndex:];
UITabBarItem *item1 = [tabBar.items objectAtIndex:];
UITabBarItem *item2 = [tabBar.items objectAtIndex:];
UITabBarItem *item3 = [tabBar.items objectAtIndex:]; item0.image = [[UIImage imageNamed:@"shouye2"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
item0.selectedImage = [[UIImage imageNamed:@"shouye1"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; item1.image = [[UIImage imageNamed:@"shoucang2"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
item1.selectedImage = [[UIImage imageNamed:@"shoucang1"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; item2.image = [[UIImage imageNamed:@"xiaoxi2"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
item2.selectedImage = [[UIImage imageNamed:@"xiaoxi1"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; item3.image = [[UIImage imageNamed:@"wode2"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
item3.selectedImage = [[UIImage imageNamed:@"wode1"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; [[UITabBarItem appearance] setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys:
[UIColor redColor],
UITextAttributeTextColor, nil] forState:UIControlStateSelected];
}