title: Swift TabBar Item color and background color
body: <p>I'm trying to set the icon color and background color of an individual item on my TabBar within the TabBarController. </p>
  
  <p>I have 5 icons on my TabBar, 4 of which i've set the color for, it's just this last icon that i'm struggling with. I've attached a link below of an image to show what i'm trying to achieve.</p>
  
  <p>The specific icon is (the one in the middle of the image) for my camera feed, this icon i would like to be white and the background to be red.
  My code so far is such -
  On my TabBarController:</p>
  
  <pre><code>var imageNames = ["FeedIcon", "ExploreIcon", "CameraIcon", "ActivityIcon", "MyProfileIcon"]
  
      let tabItems = tabBar.items as! [UITabBarItem]
      for (index, value) in enumerate(tabItems)
      {
         var imageName = imageNames[index]
          value.image = UIImage(named: imageName)
          value.imageInsets = UIEdgeInsetsMake(5.0, 0, -5.0, 0)
  
      }
      //for below i've used a extension for imageWithColor to set the color of my icons
      for tabItems in self.tabBar.items as! [UITabBarItem] {
          if let image = tabItems.image {
              tabItems.image = image.imageWithColor(UIColor(red: 57.0/255.0, green: 57.0/255.0, blue: 57.0/255.0, alpha: 1.0)).imageWithRenderingMode(.AlwaysOriginal)
          }
      }
  </code></pre>
  
  <p>My Extension:</p>
  
  <pre><code>    extension UIImage {
      func imageWithColor(tintColor: UIColor) -&gt; UIImage {
          UIGraphicsBeginImageContextWithOptions(self.size, false, self.scale)
  
          let context = UIGraphicsGetCurrentContext() as CGContextRef
          CGContextTranslateCTM(context, 0, self.size.height)
          CGContextScaleCTM(context, 1.0, -1.0);
          CGContextSetBlendMode(context, kCGBlendModeNormal)
  
          let rect = CGRectMake(0, 0, self.size.width, self.size.height) as CGRect
          CGContextClipToMask(context, rect, self.CGImage)
          tintColor.setFill()
          CGContextFillRect(context, rect)
  
          let newImage = UIGraphicsGetImageFromCurrentImageContext() as UIImage
          UIGraphicsEndImageContext()
  
          return newImage
      }
  }
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/lpo7k.png" alt="enter image description here"></p>