在storyboard里逐项设置了图片,咦,怎么是颜色?别急,慢慢来
找到你的tabbarcontroller指向的viewcontroller,在viewdidload里做如下事,搞定
1 - (void)viewDidLoad { 2 [super viewDidLoad]; 3 4 UITabBar *tabBar = self.tabBar; 5 6 7 UIView *backView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tabBar.frame.size.width, tabBar.frame.size.height)]; 8 backView.backgroundColor = [UIColor whiteColor]; 9 [tabBar insertSubview:backView atIndex:0]; 10 11 UITabBarItem *item0 = [tabBar.items objectAtIndex:0]; 12 UITabBarItem *item1 = [tabBar.items objectAtIndex:1]; 13 UITabBarItem *item2 = [tabBar.items objectAtIndex:2]; 14 UITabBarItem *item3 = [tabBar.items objectAtIndex:3]; 15 16 item0.image = [[UIImage imageNamed:@"shouye2"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; 17 item0.selectedImage = [[UIImage imageNamed:@"shouye1"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; 18 19 item1.image = [[UIImage imageNamed:@"shoucang2"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; 20 item1.selectedImage = [[UIImage imageNamed:@"shoucang1"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; 21 22 item2.image = [[UIImage imageNamed:@"xiaoxi2"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; 23 item2.selectedImage = [[UIImage imageNamed:@"xiaoxi1"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; 24 25 item3.image = [[UIImage imageNamed:@"wode2"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; 26 item3.selectedImage = [[UIImage imageNamed:@"wode1"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; 27 28 29 [[UITabBarItem appearance] setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys: 30 [UIColor redColor], 31 UITextAttributeTextColor, nil] forState:UIControlStateSelected]; 32 }
转载请注明出处.
写博客的目的:记录,升华,量变到质变