How to render a whole UITableView as an UIImage in iOS?

后端 未结 13 2169
太阳男子
太阳男子 2020-12-17 23:54

I have simple UITableView with some data. The table\'s height is greater than the screen size. Now I need to catch screenshot of this table (a whole table). I k

13条回答
  •  猫巷女王i
    2020-12-18 00:26

    My solution for Swift 4 !

    import Foundation
    import UIKit
    
    extension UITableView {
    
        func asFullImage() -> UIImage? {
    
            guard self.numberOfSections > 0, self.numberOfRows(inSection: 0) > 0 else {
                return nil
            }
    
            self.scrollToRow(at: IndexPath(row: 0, section: 0), at: .top, animated: false)
    
            var height: CGFloat = 0.0
            for section in 0..

提交回复
热议问题