title: Swift: Background color change in selected segment of UISegmentControl
body: <p>In my Swift app, I dont know how to change BGColor for selected segment alone, in UISegmentControl. I have tried a lot, only tint color is changing. I got success in Objective - C. I dont know how to convert that to SWIFT. Kindly guide me. My codings below:</p>
  
  <p><strong>Objective C</strong></p>
  
  <pre><code>- (IBAction)mySeg:(UISegmentedControl *)sender {
  
      for (int i=0; i&lt;[sender.subviews count]; i++)
      {
          if ([[sender.subviews objectAtIndex:i]isSelected] )
          {
              UIColor *tintcolor=[UIColor colorWithRed:255.0/255.0 green:0/255.0 blue:0/255.0 alpha:1.0];
              [[sender.subviews objectAtIndex:i] setTintColor:tintcolor];  //HERE SELECTED SEGMENT COLOR ALONE CHANGING
          }
          else
          {
              [[sender.subviews objectAtIndex:i] setTintColor:nil];
          }
      }
  }
  </code></pre>
  
  <p><strong>Swift</strong></p>
  
  <pre><code>@IBAction func mySegAcn(sender: UISegmentedControl) {
  for(var i : Int = 0; i &lt; sender.subviews.count; i++)
  {
      if((sender.subviews[i].isSelected) != nil) 
      {
          //var tint_Color =  UIColor(red: 1.0, green: 0, blue: 0, alpha: 1.0)
  
          (sender.subviews[i] as! UIView).tintColor = UIColor .redColor()  //HERE WHOLE TINT COLOR IS CHANGING
      }
  
      else
      {
  
          (sender.subviews[i] as! UIView).tintColor = nil
      }
  }
  }
  </code></pre>
  
  <p><strong>Output</strong></p>
  
  <p><a href="https://i.stack.imgur.com/AFCMV.png" rel="noreferrer"><img src="https://i.stack.imgur.com/AFCMV.png" alt="enter image description here"></a></p>