44 lines
1.1 KiB
Swift
44 lines
1.1 KiB
Swift
//
|
|
// UITableView+Extesion.swift
|
|
// DLSDK
|
|
//
|
|
// Created by osell on 2023/5/31.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
public extension UITableView {
|
|
|
|
func restGroupStyle() {
|
|
tableHeaderView = UIView(frame: CGRect(x: 0, y: 0, width: 0, height: CGFLOAT_MIN))
|
|
tableFooterView = UIView(frame: CGRect(x: 0, y: 0, width: 0, height: CGFLOAT_MIN))
|
|
estimatedSectionHeaderHeight = 0
|
|
estimatedSectionFooterHeight = 0
|
|
if #available(iOS 15.0, *) {
|
|
sectionHeaderTopPadding = 0
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
extension UITableView {
|
|
func scrollToTop(animated: Bool = false) {
|
|
let topOffset: CGPoint
|
|
|
|
if self.style == .grouped {
|
|
topOffset = CGPoint(x: 0, y: -self.safeAreaInsets.top)
|
|
} else {
|
|
if #available(iOS 11.0, *) {
|
|
topOffset = CGPoint(x: 0, y: -self.adjustedContentInset.top)
|
|
} else {
|
|
topOffset = CGPoint(x: 0, y: -self.contentInset.top)
|
|
}
|
|
}
|
|
|
|
// 确保在主线程执行
|
|
DispatchQueue.main.async {
|
|
self.setContentOffset(topOffset, animated: animated)
|
|
}
|
|
}
|
|
}
|