ios8中UITabbarController的图片颜色处理

来源:互联网 发布:脉脉软件安全吗 编辑:程序博客网 时间:2024/05/03 17:30


<strong>我们知道。在IOS8中,对于UITabbarController的方法,有些已经不能用了,下面把最新的方法介绍如下:</strong>

1.

用下面的代码,可以对tabbaritem进行图片设定,即没有点击和点击之后的图片分别显示如何:

    UIImage * normalImage = [[UIImage imageNamed:@"abbbab"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];    UIImage * selectImage = [[UIImage imageNamed:@"aaaaaaaaSelected"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];    UITabBarItem * tabBarItemlala = [[UITabBarItem alloc]initWithTitle:@"haha" image:normalImage selectedImage:selectImage];    self.tabBarItem = tabBarItemlala;
2.

用下面的代码,可以对字体的颜色进行设定成自己想要的颜色。

    [self.tabBarItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor greenColor], NSForegroundColorAttributeName, nil] forState:UIControlStateNormal];    [self.tabBarItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor redColor], NSForegroundColorAttributeName, nil] forState:UIControlStateSelected];
上面两个功能的截图如下:

他们的点击和未点击情况下的两种形式

3.

将所有的图片和文字在选中的时候变成自己设定的颜色

    [self.tabBarController.tabBar setTintColor:[UIColor redColor]];
如图:




4.背景色的修改:

    UIView *bgView = [[UIView alloc] initWithFrame:self.tabBarController.tabBar.bounds];    bgView.backgroundColor = [UIColor redColor];    [self.tabBarController.tabBar insertSubview:bgView atIndex:1];    self.tabBarController.tabBar.opaque = YES;
这里注意atIndex:1。这里是1哦,不是0,也不是2.大家可以把1换成其他的看看效果。

下面的截图:



0 0
原创粉丝点击