I have this function which takes a screenshot of whats in imageView
@IBAction func screenShotMethod(sender: UIButton) {
//Create the UIImage
UIGraphicsBeginImageContextWithOptions(imageView.frame.size, false, 0.0)
imageView.layer.renderInContext(UIGraphicsGetCurrentContext())
//I think here is where I could add the other imageView if I could name it properly.
let image = UIGraphicsGetImageFromCurrentImageContext()
}
I think I need something like:
UIButton(named:"monkey.png").layer.renderInContext(UIGraphicsGetCurrentContext())
right after I add the imageView to the context but Im not sure how to do this correctly. As you can see, I am trying to add an imageView named monkey.png that exists on the main.storyboard.
Any suggestions?
I'm not sure, what the problem was, why your approach didn't work for you, but adding the following line instead of the comment you placed in the code ("I think here is where..."), does what I understand you are trying to achieve:
UIImageView(image: UIImage(named: "monkey.png")).layer.renderInContext(UIGraphicsGetCurrentContext())
so it would make your whole method look like this:
@IBAction func screenShotMethod(sender: UIButton) {
UIGraphicsBeginImageContextWithOptions(imageView.frame.size, false, 0.0)
imageView.layer.renderInContext(UIGraphicsGetCurrentContext())
UIImageView(image: UIImage(named: "monkey.png")).layer.renderInContext(UIGraphicsGetCurrentContext())
let image = UIGraphicsGetImageFromCurrentImageContext()
// Do something with the image ;)
}