HCRefresh是一个轻量级的刷新框架。使用简单方便,并支持自定义刷新视图。
pod 'HCRefresh'
[scrollView hc_addHeaderRefreshWithTarget:self actionSelector:@selector(headerRefresh)];
[scrollView hc_addFooterRefreshWithTarget:self actionSelector:@selector(footerRefresh)];
[scrollView hc_addHeaderRefreshWithActionBlock:^{
}];
[scrollView hc_addFooterRefreshWithActionBlock:^{
}];
//停止下拉刷新(不显示更新信息)
[_scrollView hc_stopHeaderRefresh];
//停止下拉刷新(显示更新信息)
[_scrollView hc_stopHeaderRefreshAndShowMessage:@"更新了10条信息"];
//停止上部刷新
[_scrollView hc_stopFooterRefresh];
//顶部刷新文字的颜色(默认灰色)
[HCRefreshManager shareManager].refreshTitleColor = HC_UICOLOR_RGB(100, 100, 100);
//顶部显示的刷新文字内容
[HCRefreshManager shareManager].refreshTitle = @"HCRefresh";
//顶部刷新文字的字体(默认系统加粗字体24号)
[HCRefreshManager shareManager].refreshTitleFont = [UIFont boldSystemFontOfSize:24];
//顶部刷新文字在显示动画时的高亮颜色(默认白色)
[HCRefreshManager shareManager].refreshTitleTinColor = HC_UICOLOR_RGB(255, 255, 255);
//更多设置请参照代码注释
//...
上拉以及下拉刷新均可设置为自定义的View视图,步骤如下:
自定义CustomRefreshView类
@interface CustomRefreshView()<HCRefreshCustomViewDelegate>
@end
@implementation CustomRefreshView
{
UILabel *titleLabel;
}
-(instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self.backgroundColor = [[UIColor purpleColor] colorWithAlphaComponent:0];
UILabel *label = [[UILabel alloc] initWithFrame:self.bounds];
label.font = [UIFont systemFontOfSize:15];
label.textColor = [UIColor whiteColor];
label.textAlignment = NSTextAlignmentCenter;
[self addSubview:label];
titleLabel = label;
}
return self;
}
#pragma mark -HCRefreshCustomViewDelegate代理
-(void)hcRefreshViewProgressChangedWithProgress:(float)progress
{
self.backgroundColor = [[UIColor purpleColor] colorWithAlphaComponent:progress];
}
-(void)hcRefreshViewStateChangedWithNewState:(HCRefreshState)newState
{
switch (newState) {
case HCRefreshState_Normal: //常规状态
{
titleLabel.text = @"上拉加载更多";
}
break;
case HCRefreshState_PrepareRefresh: //准备刷新状态
{
titleLabel.text = @"松开即可刷新";
}
break;
case HCRefreshState_StartRefresh: //正在刷新状态
{
titleLabel.text = @"正在刷新";
}
break;
default:
break;
}
}
将CustomRefreshView设置为刷新视图
[scrollView hc_addFooterRefreshWithTarget:self actionSelector:@selector(footerRefresh) customFooterView:[CustomRefreshView class]];