MoviaBox/Thimra/Base/Extension/UIScrollView+SPRefresh.swift
2025-04-21 14:30:28 +08:00

65 lines
1.8 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// UIScrollView+SPRefresh.swift
// Thimra
//
// Created by on 2025/4/19.
//
import UIKit
extension UIScrollView {
func sp_addRefreshHeader(insetTop: CGFloat = 0, block: (() -> Void)?) {
self.mj_header = MJRefreshNormalHeader(refreshingBlock: {
block?()
})
self.mj_header?.ignoredScrollViewContentInsetTop = insetTop
}
func sp_addRefreshFooter(insetBottom: CGFloat = 0, block: (() -> Void)?) {
let footer = MJRefreshAutoNormalFooter(refreshingBlock: {
block?()
})
footer.ignoredScrollViewContentInsetBottom = insetBottom
// footer.stateLabel?.font = .text_sm
// footer.stateLabel?.textColor = .system_text_secondary_300
self.mj_footer = footer
}
// func sp_setRefreshFooterTitle(title: String = NSLocalizedString("", comment: ""), state: MJRefreshState) {
// (self.mj_footer as? MJRefreshAutoStateFooter)?.setTitle(title, for: state)
// }
func sp_addRefreshBackFooter(insetBottom: CGFloat = 0, block: (() -> Void)?) {
self.mj_footer = MJRefreshBackNormalFooter(refreshingBlock: {
block?()
})
self.mj_footer?.ignoredScrollViewContentInsetBottom = insetBottom
}
func sp_endHeaderRefreshing() {
self.mj_header?.endRefreshing()
}
func sp_endFooterRefreshing() {
if self.mj_footer?.state == .noMoreData { return }
self.mj_footer?.endRefreshing()
}
///
func sp_resetNoMoreData() {
self.mj_footer?.resetNoMoreData()
}
func sp_endRefreshingWithNoMoreData() {
// self.mj_footer?.state = .noMoreData
self.mj_footer?.endRefreshingWithNoMoreData()
}
}