其实iOS Tabbar的可定制性非常高,我们没有必要重复造轮子,下面是笔者收集的一些tabbar的常用设置,希望对大家有所帮助。
iOS7设置如下:
[self.tabBarController.tabBarsetSelectedImageTintColor:[UIColor greenColor]];
ios8中如下设置:
self.tabBar.tintColor=[UIColor greenColor];
消除tabbar边框
在appdelegate的程序启动处:
[[UITabBar appearance] setShadowImage:[[UIImage alloc]init]];
[[UITabBar appearance] setBackgroundImage:[[UIImage alloc]init]];
设置tabbar item原始图标与原始选中图标,而不是系统自动填充的颜色
// 拿到 TabBar 在拿到想应的item UITabBar *tabBar = _tabBarController.tabBar; UITabBarItem *item0 = [tabBar.items objectAtIndex:0]; UITabBarItem *item1 = [tabBar.items objectAtIndex:1]; UITabBarItem *item2 = [tabBar.items objectAtIndex:2]; UITabBarItem *item3 = [tabBar.items objectAtIndex:3]; // 对item设置相应地图片 item0.selectedImage = [[UIImage imageNamed:@"recognize-1"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];; item0.image = [[UIImage imageNamed:@"recognize"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; item1.selectedImage = [[UIImage imageNamed:@"life-1"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];; item1.image = [[UIImage imageNamed:@"life"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; item2.selectedImage = [[UIImage imageNamed:@"edit-1"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];; item2.image = [[UIImage imageNamed:@"edit"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; item3.selectedImage = [[UIImage imageNamed:@"setting-1"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];; item3.image = [[UIImage imageNamed:@"setting"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
设置tabbar背景图片
UIView *backView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, Main_Screen_Width, 49)]; backView.backgroundColor = [UIColor redColor]; [self.tabBar insertSubview:backView atIndex:0]; self.tabBar.opaque = YES;
原文地址:http://blog.csdn.net/xanxus46/article/details/46459005