本文讲述tabBar的自定制,设置tabBar的items的图文,代码如下:
- (void)addChildViewController:(UIViewController *)viewController imageName:(NSString *)imageName selectedImageName:(NSString *)selectedImageName title:(NSString *)title{
viewController.tabBarItem.image = [UIImage imageNamed:imageName];//normal - image
viewController.tabBarItem.title = title;//设置title
//改变UITabBarItem 字体颜色
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor lightGrayColor], NSForegroundColorAttributeName, nil] forState:UIControlStateNormal];//normal - titleColor
[[UITabBarItem appearance] setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys:[UIColor colorWithRed:247/255.0 green:120/255.0 blue:122/255.0 alpha:1.0],NSForegroundColorAttributeName, nil]forState:UIControlStateSelected];//selected - titleColor
UIImage *image = [UIImage imageNamed:selectedImageName];
image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];//显示原图配置,去渲染影响
viewController.tabBarItem.selectedImage = image;//selected - image
// viewController.tabBarItem.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);//移动tabBar图片
viewController.tabBarItem.titlePositionAdjustment = UIOffsetMake(0, -5);//移动tabBar文字
[self addChildViewController:viewController];
}
更多分享,敬请关注!
荆轲刺秦王!
网友评论