How to take a screenshot of a pickerViewController and UIView?

对着背影说爱祢 提交于 2019-12-01 14:30:33

you should write a extension for view's screenshot.Extension's return value is UIImage.You can print UIImage to UIImageview. Also if you want to, you can call here a button action.

import UIKit


class VideoContentController: UIViewController{
      override func viewDidLoad() 
    {
        super.viewDidLoad()
        self.viewScreenShot()
    }
     func viewScreenShot()
    {
     let image = self.youtView.takeScreenShot()
     self.yourImageView.image = image
    }


}    

extension UIView {

        func takeScreenShot() -> UIImage {
            UIGraphicsBeginImageContextWithOptions(bounds.size, false, UIScreen.main.scale)

            drawHierarchy(in: self.bounds, afterScreenUpdates: true)

            // old style: layer.renderInContext(UIGraphicsGetCurrentContext())

            let image = UIGraphicsGetImageFromCurrentImageContext()
            UIGraphicsEndImageContext()
            return image!
        }
    }

Enjoy it :)

func ScreenCapturing() 
{
  UIGraphicsBeginImageContextWithOptions(view.bounds.size, false, UIScreen.main.scale)
    view.layer.render(in: UIGraphicsGetCurrentContext()!)
    let image = UIGraphicsGetImageFromCurrentImageContext()
    UIGraphicsEndImageContext()
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!