Search code examples
iosios-simulator

Where can you paste images in the iPhone simulator?


I have a demo where I need to prove that images can be copied and pasted inside an iPhone simulator.

What apps, or which types of elements can be used which will allow me to paste a copied image in the simulator.

Note, I know how to copy images in the simulator, I just don't have SMS or Whatsapp to paste them into as I would on an iPhone.


Solution

  • You can create simple application with a UIImageView inside the ViewController and just override the paste function of the UIViewController. In my case, I added a tap gesture to my UIImageView to display the context menu. And when the paste function is called, I get the copied image from the UIPasteBoard.

    class ViewController : UIViewController
    {
      @IBOutlet weak var imgView : UIImageView!
    
      override func viewDidLoad()
      {
        super.viewDidLoad()
    
        imgView.addGestureRecognizer(UITapGestureRecognizer(target: self,action:#selector(HomeViewController.showContextMenu(_:))))
      }
    
      override func paste(sender: AnyObject?)
      {
        imgView.image = UIPasteboard.generalPasteboard().image
      }
    
    
      override func canBecomeFirstResponder() -> Bool 
      {
        return true
      }
    
      func showContextMenu(gesture: UITapGestureRecognizer)
      {
        if let sender = gesture.view
        {
          let menu = UIMenuController.sharedMenuController()
          menu.setTargetRect(sender.frame, inView: self.view)
          menu.setMenuVisible(true, animated: true)
          becomeFirstResponder()
        }
      }
    }