title: How to fit an image inside SegmentController programmatically - Swift
body: <p>I need to setup an image inside SegmentController - Swift.</p>
  
  <pre><code>    let testTypeSegmentedControl: UISegmentedControl = {
  
      let types = [“Green”, “Blue”] // v_concreteSelectedIndex
      let sc = UISegmentedControl(items: types)
      sc.setImage((UIImage(named: "Green_Main.png")), forSegmentAt: 0)
  
      sc.selectedSegmentIndex = 0
      sc.translatesAutoresizingMaskIntoConstraints = false
      sc.tintColor = .black
  
      return sc
  }()
  </code></pre>
  
  <p>How to fix the image properly inside the segment controller.</p>
  
  <p>I tried:</p>
  
  <pre><code>sc.contentMode = .scaleAspectFill
  </code></pre>
  
  <p>but seems it didn't worked well.</p>
  
  <p>I tried to use constrain but I have no idea how to do it.</p>
  
  <p>Any advise how to proceed?</p>