title: swift 3 content mode
body: <p>I have a problem with xcode: I created a draw app where you can draw on the pictures, when I open a picture and I click to draw, the image stretches,
  the same thing if I change content mode (aspectFit, aspectFill)
  I forget something?
  how to set up the content mode correctly?</p>
  
  <p>This is my code:</p>
  
  <pre><code>import UIKit
  import Photos
  
  class ViewController: UIViewController {
  
      @IBOutlet var imageView: UIImageView!
      @IBOutlet var toolIcon: UIButton!
      @IBOutlet var tempImage: UIImageView!
  
      var lastPoint = CGPoint.zero
      var swiped = false
  
      var red: CGFloat = 0.0
      var green: CGFloat = 0.0
      var blue: CGFloat = 0.0
  
      var brushWidth:CGFloat = 10.0
      var opacity:CGFloat = 1.0
  
      var tool: UIImageView!
      var isDrawing = true
      var selectedImage: UIImage!
  
  
      override func viewDidLoad() {
          super.viewDidLoad()
  
          // Do any additional setup after loading the view.
          imageView.contentMode = UIViewContentMode.scaleAspectFill
          tempImage.contentMode = UIViewContentMode.scaleAspectFill
  
          tool = UIImageView()
          tool.frame = CGRect(x:self.view.bounds.size.width, y: self.view.bounds.size.height, width: 38, height: 38)
          //tool.image = #imageLiteral(resourceName: "Pen")
          self.view.addSubview(tool)
      }
      override func touchesBegan(_ touches: Set&lt;UITouch&gt;, with event: UIEvent?){
          swiped = false
          if let touch = touches.first {
              lastPoint = touch.location(in: self.view)
          }
      }
  
      func drawLines(fromPoint:CGPoint, toPoint:CGPoint){
          UIGraphicsBeginImageContext(self.view.frame.size)
          tempImage.image?.draw(in: CGRect(x:0, y:0, width: self.view.frame.width,height: self.view.frame.height))
          let context = UIGraphicsGetCurrentContext()
  
          context?.move(to:CGPoint(x:fromPoint.x,y:fromPoint.y))
          context?.addLine(to: CGPoint(x:toPoint.x, y: toPoint.y))
          tool.center = toPoint
  
          context?.setBlendMode(CGBlendMode.normal)
          context?.setLineCap(CGLineCap.round)
          context?.setLineWidth(brushWidth)
          context?.setStrokeColor(UIColor(red: red, green: green, blue: blue, alpha: 1.0).cgColor)
          context?.strokePath()
  
          tempImage.image = UIGraphicsGetImageFromCurrentImageContext()
          tempImage.alpha = opacity
          UIGraphicsEndImageContext()
  
      }
  
      override func touchesMoved(_ touches: Set&lt;UITouch&gt;, with event: UIEvent?){
          swiped = true
  
          if let touch = touches.first {
              let currentPoint = touch.location(in: self.view)
              drawLines(fromPoint: lastPoint, toPoint: currentPoint)
  
              lastPoint = currentPoint
          }
  
      }
  
      override  func touchesEnded(_ touches: Set&lt;UITouch&gt;, with event: UIEvent?) {
          if !swiped {
              drawLines(fromPoint: lastPoint, toPoint: lastPoint)
          }
  
          // Merge tempImageView into mainImageView
          UIGraphicsBeginImageContext(imageView.frame.size)
          imageView.image?.draw(in: CGRect(x: 0, y: 0, width: view.frame.size.width, height: view.frame.size.height), blendMode: CGBlendMode.normal, alpha: 1.0)
          tempImage.image?.draw(in: CGRect(x: 0, y: 0, width: view.frame.size.width, height: view.frame.size.height), blendMode: CGBlendMode.normal, alpha: opacity)
          imageView.image = UIGraphicsGetImageFromCurrentImageContext()
          UIGraphicsEndImageContext()
  
          tempImage.image = nil
  
      }
  
      @IBAction func reset(_ sender: Any) {
          self.imageView.image = nil
      }
  
  
  
      @IBAction func colorPicked(_ sender: UIButton) {
          if sender.tag == 0 {
              (red,green,blue) = (1,0,0)
          }else if sender.tag == 1 {
              (red,green,blue) = (0,1,0)
          }else if sender.tag == 2{
              (red,green,blue) = (0,0,1)
          }else if sender.tag == 3 {
              (red,green,blue) = (1,0,1)
          }else if sender.tag == 4{
              (red,green,blue) = (1,1,0)
          }else if sender.tag == 5 {
              (red,green,blue) = (0,1,1)
          }else if sender.tag == 6{
              (red,green,blue) = (1,1,1)
          }else if sender.tag == 7 {
              (red,green,blue) = (0,0,0)
          }
          }
      @IBAction func save(_ sender: Any) {
          let actionSheet = UIAlertController(title: "Pick your options", message: "", preferredStyle: .actionSheet)
  
          actionSheet.addAction(UIAlertAction(title: "Pick an image", style: .default, handler: { (_) in
  
              let imagePicker = UIImagePickerController()
              imagePicker.sourceType = .photoLibrary
              imagePicker.allowsEditing = false
              imagePicker.delegate = self
  
              self.present(imagePicker, animated: true, completion: nil)
  
          }))
  
          actionSheet.addAction(UIAlertAction(title: "Save your drawing", style: .default, handler: {(_) in
              if let image = self.imageView.image {
                  UIImageWriteToSavedPhotosAlbum(image, nil,nil,nil)
              }
          }))
  
          actionSheet.addAction(UIAlertAction(title: "Cancel", style: .default, handler: nil))
          present(actionSheet, animated: true, completion: nil)
      }
  
      @IBAction func erase(_ sender: Any) {
          if (isDrawing) {
              (red,green,blue) = (1,1,1)
              tool.image = #imageLiteral(resourceName: "Gomma")
              toolIcon.setImage(#imageLiteral(resourceName: "Pen"), for: .normal)
  
          }else {
              (red,green,blue) = (0,0,0)
              tool.image = nil
              toolIcon.setImage(#imageLiteral(resourceName: "Gomma"), for: .normal)
          }
          isDrawing = !isDrawing
      }
  
  
      @IBAction func setting(_ sender: Any) {
      }
      override func didReceiveMemoryWarning() {
          super.didReceiveMemoryWarning()
          // Dispose of any resources that can be recreated.
      }
  
      override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
          super.prepare(for: segue, sender: sender)
  
          let settingsVc = segue.destination as! SettingViewController
          settingsVc.delegate = self
          settingsVc.red = red
          settingsVc.green = green
          settingsVc.blue = blue
  
          settingsVc.brush = brushWidth
          settingsVc.opacity = opacity
      }
  }
  
  
  extension ViewController:UINavigationControllerDelegate,UIImagePickerControllerDelegate,SettingsVCDelegate {
      func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
          if let imagePicked = info[UIImagePickerControllerOriginalImage] as? UIImage  {
              self.selectedImage = imagePicked
              self.imageView.image = selectedImage
              self.tempImage.image = selectedImage
  
  
  
              dismiss(animated: true, completion: nil)
  
          }
      }
      func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
          dismiss(animated: true, completion: nil)
      }
  
      func settingsViewControllerDidFinish(_settingsVc: SettingViewController) {
          self.red = _settingsVc.red
          self.green = _settingsVc.green
          self.blue = _settingsVc.blue
          self.brushWidth = _settingsVc.brush
          self.opacity = _settingsVc.opacity
  
      }
  }
  </code></pre>