很长一段时间都是用代码来写UITabbarController,试着用xib来写一次,但是遇到tabbar item的图标自定义的时候不知道从何入手,比如定义选定前和选定后的icon图片,这地方还是不太明显。现在用代码记录一下
[[UITabBar appearance] setBackgroundImage:[UIImage imageNamed:@"tabBar.png"]];
或
[[self.RootTabbarController tabBar] setBackgroundImage:[UIImageimageNamed:@"tabbar.png"]]; ITabBarController *tabController = (UITabBarController *)self.window.rootViewController; selectedImage = [UIImage imageNamed:@"contact"];
unselectedImage = [UIImage imageNamed:@"contact"];
UITabBarItem *item3 = [tabBar.items objectAtIndex:2];
[item3 setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
COLOR_APP,UITextAttributeTextColor, nil]
forState:UIControlStateNormal]; // [item3 setFinishedSelectedImage:selectedImage
// withFinishedUnselectedImage:unselectedImage];
[item3 setImage:selectedImage];
[item3 setSelectedImage:selectedImage];
这个图片上标记了tabbar item的各种属性
UIimageWithRenderingMode:UIImageRenderingModeAlwaysTemplate这个作为ios7里面的新属性,应该注意
很多时候在ios7上使用自定义的tabbar,tabbar顶部会出现一个线,此时解决方案
[[UITabBarappearance] setShadowImage:[[UIImagealloc] init]];
原理是用一个一像素的线图覆盖。