// // SPTableView.swift // ShortPlay // // Created by 曾觉新 on 2025/4/14. // import UIKit class SPTableView: UITableView { var insetGroupedMargins: CGFloat = 12 override init(frame: CGRect, style: UITableView.Style) { super.init(frame: frame, style: style) // separatorColor = .lineColor() self.backgroundColor = .clear self.contentInsetAdjustmentBehavior = .never if style == .insetGrouped { sectionFooterHeight = 12 sectionHeaderHeight = 0.1 } else if style == .plain { if #available(iOS 15.0, *) { sectionHeaderTopPadding = 0 } } } required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } ///修改 insetGrouped 的边距 参考https://github.com/QMUI/QMUIDemo_iOS/blob/master/QMUI/QMUIKit/UIKitExtensions/UITableView%2BQMUI.m override var layoutMargins: UIEdgeInsets { set { super.layoutMargins = newValue } get { var margins = super.layoutMargins if #available(iOS 13.0, *) { if self.style == .insetGrouped { margins.left = self.safeAreaInsets.left + insetGroupedMargins margins.right = self.safeAreaInsets.right + insetGroupedMargins } } return margins } } }