我有这个功能,它在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()
}
我想我需要这样的东西:
UIButton(named:"monkey.png").layer.renderInContext(UIGraphicsGetCurrentContext())
我将imageView添加到上下文后,但我不知道如何正确地执行此操作。如您所见,我正在尝试添加一个名为monkey.png的imageView,它存在于main.storyboard上。
有什么建议吗?
答案 0 :(得分:1)
我不确定,问题是什么,为什么你的方法不适合你,但是添加以下行而不是你在代码中放置的注释(“我想这里是......”) ,我理解你正在努力实现的目标:
UIImageView(image: UIImage(named: "monkey.png")).layer.renderInContext(UIGraphicsGetCurrentContext())
所以它会使你的整个方法看起来像这样:
@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 ;)
}