Ios Swift-更改选项卡栏图标(如Instagram)的背景色

Ios Swift-更改选项卡栏图标(如Instagram)的背景色,ios,swift,uitabbarcontroller,instagram,uicolor,Ios,Swift,Uitabbarcontroller,Instagram,Uicolor,我想自定义选项卡栏的外观。我想在Instagram应用程序上重新创建外观,对于那些不熟悉该应用程序中选项卡栏的人,请参见以下图片:。这是我当前的选项卡栏: 我已经设置了背景色和图像的位置,但我希望所选的选项卡栏图标的其他部分的背景色更暗。此外,我希望无论是否选中,中心选项卡栏图标都是不同的颜色 为了澄清这一点,我只需要代码来更改选项卡栏图标在选中和未选中时的背景色 提前谢谢 我创建了UITabBarController的子类,并在viewDidLoad中添加了以下内容: let itemWidt

我想自定义选项卡栏的外观。我想在Instagram应用程序上重新创建外观,对于那些不熟悉该应用程序中选项卡栏的人,请参见以下图片:。这是我当前的选项卡栏:

我已经设置了背景色和图像的位置,但我希望所选的选项卡栏图标的其他部分的背景色更暗。此外,我希望无论是否选中,中心选项卡栏图标都是不同的颜色

为了澄清这一点,我只需要代码来更改选项卡栏图标在选中和未选中时的背景色


提前谢谢

我创建了UITabBarController的子类,并在viewDidLoad中添加了以下内容:

let itemWidth = tabBar.frame.width / CGFloat(tabBar.items!.count)
let size : CGFloat = CGFloat(itemWidth) * CGFloat(2)
let imageView = UIImageView(frame: CGRectMake(size, 5, itemWidth-10, tabBar.frame.height-10))
let image = UIImage(named: "compose")
imageView.image = image
imageView.contentMode = .ScaleAspectFit
tabBar.insertSubview(imageView, atIndex: 2)
我只是用了一张我想要的背景色的图片。 这就是它看起来的样子:


希望这能有所帮助

看到这个真棒,谢谢@alex\u p!你知道我现在如何让中央按钮变成不同的颜色,不管它是否被选中,就像在Instagram的选项卡栏中看到的一样?尝试使用答案中的第一个
扩展名
!。项目![2] .image=UIImage().makeimagewithcolor和size
使用您需要的颜色,似乎不起作用。。。这是我的代码:
tabBar!。项目![2] .image=UIImage().makeImageWithColorAndSize(UIColor.redColor(),大小:CGSizeMake(tabBar!.frame.width/CGFloat(tabBar!.items!.count),tabBar!.frame.height))
@alex_p@shivamkaushik当然,这是我用的<代码>让itemWidth=tabBar!。frame.width/CGFloat(tabBar!.items!.count)
let size:CGFloat=CGFloat(itemWidth)*CGFloat(2)let bgView=UIView(frame:CGRectMake(size,0,itemWidth,tabBar!.frame.height))
bgView.backgroundColor=UIColor(netHex:0x015187)tabBar!。insertSubview(bgView,atIndex:2)
很抱歉延迟!