为 scrollview/tableview 提供的一个简单的顶部刷新控件。
使用 CocoaPods,将此行添加到您的 Podfile
中。
pod 'FMTopReflesh'
然后运行 pod install
,然后您就完成了!
或者把 FMTopRefleshControl.h FMTopRefleshControl.m 复制到您的项目。
实现 FMTopRefleshControlTopView
协议
- (void)pullToReflesh {
//self.backgroundColor = [UIColor blueColor];
self.textLabel.text = @"pull to relfesh";
}
- (void)releaseToReflesh {
//self.backgroundColor = [UIColor yellowColor];
self.textLabel.text = @"release to relfesh";
}
- (void)startReflesh {
//self.backgroundColor = [UIColor redColor];
[self.indicator startAnimating];
self.textLabel.text = @"relfesh...";
}
- (void)refleshFinished {
//self.backgroundColor = [UIColor whiteColor];
[self.indicator stopAnimating];
self.textLabel.text = nil;
}
配置刷新控件
self.refleshControl = [[FMTopRefleshControl alloc] initWithScrollView:v withRefleshCallback:^(FMTopRefleshControl *control) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[control endReflesh];
});
} withTopView:[[CustomTopRefleshView alloc] initWithFrame:[UIScreen mainScreen].bounds]];