TSBaseCollectionView.swift 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. //
  2. // TSBaseCollectionView.swift
  3. // Pods
  4. //
  5. // Created by 100Years on 2025/6/17.
  6. //
  7. open class TSBaseCollectionView: UICollectionView {
  8. // override var effectiveUserInterfaceLayoutDirection: UIUserInterfaceLayoutDirection {
  9. // return kIsRTL ? .rightToLeft : .leftToRight
  10. // }
  11. // MARK: - 初始化
  12. override public init(frame: CGRect, collectionViewLayout layout: UICollectionViewLayout) {
  13. super.init(frame: frame, collectionViewLayout: layout)
  14. commonInit()
  15. }
  16. required public init?(coder: NSCoder) {
  17. super.init(coder: coder)
  18. commonInit()
  19. }
  20. // MARK: - 公共配置
  21. private func commonInit() {
  22. // 通用配置
  23. backgroundColor = .systemBackground
  24. keyboardDismissMode = .onDrag
  25. if kIsRTL {
  26. semanticContentAttribute = .forceRightToLeft
  27. }
  28. backgroundColor = .clear
  29. showsVerticalScrollIndicator = false
  30. showsHorizontalScrollIndicator = false
  31. if #available(iOS 11.0, *) {
  32. contentInsetAdjustmentBehavior = .never
  33. }
  34. }
  35. }
  36. open class TSBaseCollectionViewFlowLayout: UICollectionViewFlowLayout {
  37. open override var flipsHorizontallyInOppositeLayoutDirection: Bool {
  38. return kIsRTL
  39. }
  40. }
  41. open class TSBaseTableView: UITableView {
  42. // MARK: - 初始化
  43. override public init(frame: CGRect, style: UITableView.Style) {
  44. super.init(frame: frame, style: style)
  45. commonInit()
  46. }
  47. required public init?(coder: NSCoder) {
  48. super.init(coder: coder)
  49. commonInit()
  50. }
  51. // MARK: - 公共配置
  52. private func commonInit() {
  53. if #available(iOS 11.0, *) {
  54. contentInsetAdjustmentBehavior = .never
  55. }
  56. if #available(iOS 15.0, *) {
  57. sectionHeaderTopPadding = 0
  58. }
  59. if kIsRTL {
  60. semanticContentAttribute = .forceRightToLeft
  61. }
  62. separatorStyle = .none
  63. backgroundColor = .clear
  64. estimatedRowHeight = 0
  65. estimatedSectionHeaderHeight = 0
  66. estimatedSectionFooterHeight = 0
  67. showsVerticalScrollIndicator = false
  68. showsHorizontalScrollIndicator = false
  69. backgroundColor = .clear
  70. if tableFooterView == nil {
  71. tableFooterView = UIView(frame: CGRect(x: 0, y: 0, width: 0, height: CGFLOAT_MIN))
  72. }
  73. }
  74. }