1:如图一下效果
代码如下:
QRcodeViewController *threeViewController
= [[QRcodeViewControlleralloc]init];
UINavigationController *threeNavigationController
= [[UINavigationControlleralloc]initWithRootViewController:threeViewController];
threeNavigationController.navigationBar.barStyle =UIBarStyleBlack;
UIImage* image = [[UIImageimageNamed:@"btn_saoyisao_default"]
imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; //这两个地方一定要加上
UIImage* selectedImage = [[UIImageimageNamed:@"btn_saoyisao_enter"]
imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
UITabBarItem* tabBarItemL = [[UITabBarItemalloc]initWithTitle:nil
image:imageselectedImage:selectedImage];
threeNavigationController.tabBarItem=tabBarItemL;
threeNavigationController.tabBarItem.imageInsets =UIEdgeInsetsMake(5,0, -5,0);
在项目中使用UITabBarController的时候, 每个UITabBarItem都可以展示对应的图片。
UITabBarItem有两种状态, 即 选中/ 非选中状态。
如果用storyboard设置图片, 那么设置的是选中状态的图片, 并且, 它会自动的填充为深蓝色. (就是 default color)至于非选中状态呢, 它会自动的变成灰色。
这大大影响了美观。
如下:
我们想要的效果, 应该是这样的:
如果要变成这样, 需要在UITabBarController中加入如下代码:
- NSArray *items = self.tabBar.items;
- UITabBarItem *homeItem = items[0];
- homeItem.image = [[UIImage imageNamed:@"tab_buddy_nor.png"]
- imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
- homeItem.selectedImage = [[UIImage imageNamed:@"tab_buddy_press.png"]
- imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
- UITabBarItem *qqItem = items[1];
- qqItem.image = [[UIImage imageNamed:@"tab_me_nor.png"]
- imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
-
- qqItem.selectedImage = [[UIImage imageNamed:@"tab_me_press.png"]
- imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];