- An easy way to use pull-to-refresh for swift
- Getting Started
- Comment API
Now MJRefresh components
will be rerendered automatically with MJRefreshConfig.default.language
setting.
Go i18n
folder and see lots of cases. Simulator example is behind i18n tab
in right-top corner.
MJRefreshConfig.default.language = "zh-hans"
MJRefreshConfig.default.i18nFilename = "i18n File Name(not include type<.strings>)"
MJRefreshConfig.default.i18nBundle = <i18n Bundle>
- Just override
i18nDidChange
function and reset texts.
override func i18nDidChange() {
// Reset texts function
setupTexts()
// Make sure to call super after resetting texts. It will call placeSubViews for applying new layout.
super.i18nDidChange()
}
- Receiving
MJRefreshDidChangeLanguageNotification
notification.
UIScrollView
、UITableView
、UICollectionView
、WKWebView
- Installation with CocoaPods(Swift and OC):
pod 'MJRefresh', :git=>'https://github.com/fish-yan/MJRefresh-Swift'
- Installation with SPM(only for Swift):
.package(url: "https://github.com/fish-yan/MJRefresh-Swift", branch: "main")
The class of red text
in the chart:You can use them directly- The drop-down refresh control types
- Normal:
MJRefreshNormalHeader
Gif:MJRefreshGifHeader
- Normal:
- The pull to refresh control types
- Auto refresh
- Normal:
MJRefreshAutoNormalFooter
Gif:MJRefreshAutoGifFooter
- Normal:
- Auto Back
- Normal:
MJRefreshBackNormalFooter
Gif:MJRefreshBackGifFooter
- Normal:
- Auto refresh
- The drop-down refresh control types
The class of non-red text
in the chart:For inheritance,to use DIY the control of refresh
/** The Base Class of refresh control */
@objcMembers @objc(MJRefreshComponent)
open class RefreshComponent: UIView {
public var fastAnimationDuration: TimeInterval = 0.25
public var slowAnimationDuration: TimeInterval = 0.4
public var isRefreshing: Bool
public var pullingPercent: CGFloat = 0
public var isAutomaticallyChangeAlpha: Bool = false
public var refreshingBlock: RefreshComponentAction = {}
public init(block: @escaping RefreshComponentAction)
public init(target: Any, action: Selector)
public func setAnimationDisabled()
open func i18nDidChange()
open func beginRefreshing()
open func endRefreshing()
}
@objcMembers @objc(MJRefreshHeader)
open class RefreshHeader: RefreshComponent {
@objc(headerWithRefreshingBlock:)
public static func header(refreshing block: @escaping RefreshComponentAction) -> Self
@objc(headerWithRefreshingTarget: refreshingAction:)
public static func header(refreshing target: Any, action: Selector) -> Self
public var ignoredScrollViewContentInsetTop: CGFloat = 0
}
@objcMembers @objc(MJRefreshFooter)
open class RefreshFooter: RefreshComponent {
@objc(footerWithRefreshingBlock:)
public static func footer(block: @escaping RefreshComponentAction) -> Self
@objc(footerWithRefreshingTarget: refreshingAction:)
public static func footer(target: Any, action: Selector) -> Self
public var ignoredScrollViewContentInsetBottom: CGFloat = 0
// auto footer or back footer
public var autoBack = false
open func endRefreshingWithNoMoreData()
open func resetNoMoreData()
}
Swift
tableView.mj_header = RefreshNormalHeader {
//Call this Block When enter the refresh status automatically
}
或
tableView.mj_header = RefreshNormalHeader.header(refreshing: self, action: #selector(refreshAction))
// Enter the refresh status immediately
tableView.mj.header?.beginRefreshing()
tableView.mj_header?.endRefreshing()
OC Same as the original MJRefresh
self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
//Call this Block When enter the refresh status automatically
}];
或
// Set the callback(Once you enter the refresh status,then call the action of target,that is call [self loadNewData])
self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadNewData)];
// Enter the refresh status immediately
[self.tableView.mj_header beginRefreshing];
// Hide the time
header.lastUpdatedTimeLabel.hidden = YES;
// Hide the time
header.lastUpdatedTimeLabel.hidden = YES;
// Hide the status
header.stateLabel.hidden = YES;
// Set title
[header setTitle:@"Pull down to refresh" forState:MJRefreshStateIdle];
[header setTitle:@"Release to refresh" forState:MJRefreshStatePulling];
[header setTitle:@"Loading ..." forState:MJRefreshStateRefreshing];
// Set font
header.stateLabel.font = [UIFont systemFontOfSize:15];
header.lastUpdatedTimeLabel.font = [UIFont systemFontOfSize:14];
// Set textColor
header.stateLabel.textColor = [UIColor redColor];
header.lastUpdatedTimeLabel.textColor = [UIColor blueColor];
self.tableView.mj_header = [MJDIYHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadNewData)];
// Implementation reference to MJDIYHeader.h和MJDIYHeader.m
Swift
let footer = RefreshFooter {
//Call this Block When enter the refresh status automatically
}
or
let footer = RefreshNormalFooter.footer(target: self, action: #selector(loadMore))
footer.autoBack = true
tableView.mj_footer = footer
tableView.mj_footer?.endRefreshingWithNoMoreData()
tableView.mj_footer?.endRefreshing()
OC Same as the original MJRefresh
self.tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
//Call this Block When enter the refresh status automatically
}];
或
// Set the callback(Once you enter the refresh status,then call the action of target,that is call [self loadMoreData])
self.tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)];
// Hide the title of refresh status
footer.refreshingTitleHidden = YES;
// If does have not above method,then use footer.stateLabel.hidden = YES;
// Set title
[footer setTitle:@"Click or drag up to refresh" forState:MJRefreshStateIdle];
[footer setTitle:@"Loading more ..." forState:MJRefreshStateRefreshing];
[footer setTitle:@"No more data" forState:MJRefreshStateNoMoreData];
// Set font
footer.stateLabel.font = [UIFont systemFontOfSize:17];
// Set textColor
footer.stateLabel.textColor = [UIColor blueColor];
//Hidden current control of the pull to refresh
self.tableView.mj_footer.hidden = YES;
self.tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)];
MJRefreshBackGifFooter *footer = [MJRefreshBackGifFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)];
// Set the normal state of the animated image
[footer setImages:idleImages forState:MJRefreshStateIdle];
// Set the pulling state of animated images(Enter the status of refreshing as soon as loosen)
[footer setImages:pullingImages forState:MJRefreshStatePulling];
// Set the refreshing state of animated images
[footer setImages:refreshingImages forState:MJRefreshStateRefreshing];
// Set footer
self.tableView.mj_footer = footer;
self.tableView.mj_footer = [MJDIYAutoFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)];
// Implementation reference to MJDIYAutoFooter.h和MJDIYAutoFooter.m
self.tableView.mj_footer = [MJDIYBackFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)];
// Implementation reference to MJDIYBackFooter.h和MJDIYBackFooter.m
// The drop-down refresh
self.collectionView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
//Call this Block When enter the refresh status automatically
}];
// The pull to refresh
self.collectionView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
//Call this Block When enter the refresh status automatically
}];
//Add the control of The drop-down refresh
self.webView.scrollView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
//Call this Block When enter the refresh status automatically
}];
- iOS>=13.0
- iPhone \ iPad screen anyway