How to take screenshot of a UIView in swift?

后端 未结 6 1109
心在旅途
心在旅途 2020-12-07 21:03

I have a UIView named overView:

overView.frame = CGRectMake(self.view.frame.width/25, self.view.frame.height/25, self.view.frame.width/1.3, self.view.frame.h         


        
6条回答
  •  囚心锁ツ
    2020-12-07 21:40

    func screenShotMethod()->UIImage
        {
            let layer = self.view.layer
            let scale = UIScreen.main.scale
            UIGraphicsBeginImageContextWithOptions(layer.frame.size, false, scale);
    
            layer.render(in: UIGraphicsGetCurrentContext()!)
            let screenshot = UIGraphicsGetImageFromCurrentImageContext()
            UIGraphicsEndImageContext()
    
            return screenshot!
        }
    

提交回复
热议问题