zoukankan      html  css  js  c++  java
  • Swift

    效果

    源码

    //
    //  UIView+ScreensShot.swift
    //  Swift-Animations
    //
    //  Created by YouXianMing on 16/9/5.
    //  Copyright © 2016年 YouXianMing. All rights reserved.
    //
    
    import UIKit
    
    extension UIView {
    
        /**
         Get the view's screen shot, this function may be called from any thread of your app.
         
         - returns: The screen shot's image.
         */
        func screenShot() -> UIImage? {
            
            guard frame.size.height > 0 && frame.size.width > 0 else {
            
                return nil
            }
            
            UIGraphicsBeginImageContextWithOptions(frame.size, false, 0)
            layer.renderInContext(UIGraphicsGetCurrentContext()!)
            let image = UIGraphicsGetImageFromCurrentImageContext()
            UIGraphicsEndImageContext()
            
            return image
        }
    }

    使用

    //
    //  ViewController.swift
    //  ScreenShot
    //
    //  Created by YouXianMing on 16/9/5.
    //  Copyright © 2016年 YouXianMing. All rights reserved.
    //
    
    import UIKit
    
    class ViewController: UIViewController {
    
        override func viewDidLoad() {
            
            super.viewDidLoad()
            
            let redView             = UIView(frame: CGRectMake(40, 40, 200, 200))
            redView.backgroundColor = UIColor.redColor().colorWithAlphaComponent(0.5)
            view.addSubview(redView)
            
            let imageView = UIImageView(image: redView.screenShot())
            view.addSubview(imageView)
        }
    }
  • 相关阅读:
    提权小结
    《将博客搬至CSDN》
    http数据流分析
    web安全之路
    nmap原理及用法
    web渗透测试思路浅谈-----漏洞发现及利用
    web渗透测试思路浅谈-----信息收集
    渗透测试实战-Android4靶机
    从外网到内网漫游
    一次完整内网渗透
  • 原文地址:https://www.cnblogs.com/YouXianMing/p/5843924.html
Copyright © 2011-2022 走看看