现今已有越来越多的APP需要横向刷新的需求,而横向刷新加载的控件却寥寥无几,即使有也是集成起来非常的麻烦,恰巧最近项目中又用到了这个功能,所以干脆自己来造个轮子,方便大家使用。
库命名为PSRefresh,支持UIScrollView及所有UIScrollView的子类控件,UITableView(横向的tableVIew)及UICollectionView等皆可。
支持自定义文字,支持自定义gif图,可设置是否为最后一页。
本文一共提供了三种样式,分别是普通样式、gif加载样式(带有状态label)、git加载样式(不带有状态label)。
Demo展示如下:
使用时导入 "UIScrollView+PSRefresh.h"
文件即可,文件中提供的属性及接口如下:
@interface UIScrollView (PSRefresh)
/**
* 是否是最后一页
*/
@property (nonatomic, assign) BOOL isLastPage;
/**
* header背景色
*/
@property (nonatomic, strong) UIColor *refreshHeaderBackgroundColor;
/**
* footer背景色
*/
@property (nonatomic, strong) UIColor *refreshFooterBackgroundColor;
/**
* header 字体
*/
@property (nonatomic, strong) UIFont *refreshHeaderFont;
/**
* header 字体颜色
*/
@property (nonatomic, strong) UIColor *refreshHeaderTextColor;
/**
* footer 字体
*/
@property (nonatomic, strong) UIFont *refreshFooterFont;
/**
* footer 字体颜色
*/
@property (nonatomic, strong) UIColor *refreshFooterTextColor;
/**
* ********************** 以下是调用的方法 **********************
*/
/**
* 普通的刷新及加载
*/
- (void)addRefreshHeaderWithClosure:(PSRefreshClosure)closure;
- (void)addRefreshFooterWithClosure:(PSRefreshClosure)closure;
/**
* gif 图刷新及加载(带有状态提示)
*/
- (void)addGifRefreshHeaderWithClosure:(PSRefreshClosure)closure;
- (void)addGifRefreshFooterWithClosure:(PSRefreshClosure)closure;
/**
* gif 图刷新及加载(不带有状态提示)
*/
- (void)addGifRefreshHeaderNoStatusWithClosure:(PSRefreshClosure)closure;
- (void)addGifRefreshFooterNoStatusWithClosure:(PSRefreshClosure)closure;
/**
* ****************** 以下三个方法是对上面方法的再次封装 ******************
*/
/**
* 普通的刷新及加载
*/
- (void)addRefreshHeaderWithClosure:(PSRefreshClosure)headerClosure
addRefreshFooterWithClosure:(PSRefreshClosure)footerClosure;
/**
* gif 图刷新及加载(带有状态提示)
*/
- (void)addGifRefreshHeaderWithClosure:(PSRefreshClosure)headerClosure
addGifRefreshFooterWithClosure:(PSRefreshClosure)footerClosure;
/**
* gif 图刷新及加载(不带有状态提示)
*/
- (void)addGifRefreshHeaderNoStatusWithClosure:(PSRefreshClosure)headerClosure
addGifRefreshFooterNoStatusWithClosure:(PSRefreshClosure)footerClosure;
/**
* 结束刷新
*/
- (void)endRefreshing;
@end
调用时可以有两种方法,可以同时添加头部控件和尾部控件,也可以分别进行添加,方法如下(这里只列举一种调用方法,只是为了展示两种不同的调用方式):
(1) 同时添加:
- (void)normalDemo {
WeakSelf(self)
[_collectionView addRefreshHeaderWithClosure:^{
// 刷新操作
[weakSelf refreshData];
} addRefreshFooterWithClosure:^{
// 加载操作
[weakSelf loadingData];
}];
}
(2) 分别添加:
- (void)normalDemo {
WeakSelf(self)
[_collectionView addRefreshHeaderWithClosure:^{
// 刷新操作
[weakSelf refreshData];
}];
[_collectionView addRefreshFooterWithClosure:^{
// 加载操作
[weakSelf loadingData];
}];
}
总结
调用方式大致和MJRefresh相同,针对具体项目大家可以进行相应的调整。以上就是本文的全部内容,希望对大家开发IOS有所帮助。
本文标题为:iOS功能实现之列表的横向刷新加载


基础教程推荐
- iOS开发 全机型适配解决方法 2023-01-14
- IOS获取系统相册中照片的示例代码 2023-01-03
- Android实现短信验证码输入框 2023-04-29
- Flutter进阶之实现动画效果(三) 2022-10-28
- Android开发Compose集成高德地图实例 2023-06-15
- iOS中如何判断当前网络环境是2G/3G/4G/5G/WiFi 2023-06-18
- Android Compose自定义TextField实现自定义的输入框 2023-05-13
- MVVMLight项目Model View结构及全局视图模型注入器 2023-05-07
- iOS开发使用XML解析网络数据 2022-11-12
- iOS Crash常规跟踪方法及Bugly集成运用详细介绍 2023-01-18