欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

【Swift】图片裁剪

程序员文章站 2022-04-09 08:05:12
...
 /// 截图
    ///
    /// - Parameters:
    ///   - view: view
    ///   - atFrame: rect
    func imageFromView(view : UIView,atFrame:CGRect) -> UIImage {
        UIGraphicsBeginImageContext(view.frame.size)
        let context = UIGraphicsGetCurrentContext()
        context?.saveGState()
        UIRectClip(atFrame)
        view.layer.render(in: context!)
        let theImage = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
        return theImage!
    }
相关标签: 图片裁剪