Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
38 lines (32 sloc) 1017 Bytes
//
// UIScrollViewExtensions.swift
// SwifterSwift
//
// Created by camila oliveira on 22/04/18.
// Copyright © 2018 SwifterSwift
//
#if canImport(UIKit) && !os(watchOS)
import UIKit
// MARK: - Methods
public extension UIScrollView {
/// SwifterSwift: Takes a snapshot of an entire ScrollView
///
/// AnySubclassOfUIScroolView().snapshot
/// UITableView().snapshot
///
/// - Returns: Snapshot as UIimage for rendered ScrollView
var snapshot: UIImage? {
// Original Source: https://gist.github.com/thestoics/1204051
UIGraphicsBeginImageContextWithOptions(contentSize, false, 0)
defer {
UIGraphicsEndImageContext()
}
guard let context = UIGraphicsGetCurrentContext() else { return nil }
let previousFrame = frame
frame = CGRect(origin: frame.origin, size: contentSize)
layer.render(in: context)
frame = previousFrame
return UIGraphicsGetImageFromCurrentImageContext()
}
}
#endif
You can’t perform that action at this time.