123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- //
- // GHRefreshFooter.m
- // GameHelper
- //
- // Created by 青秀斌 on 16/12/29.
- // Copyright © 2016年 kylincc. All rights reserved.
- //
- #import "GHRefreshFooter.h"
- #import "UILabel+GHConfig.h"
- #import "GHThemeManager.h"
- #import "UIView+GHTheme.h"
- @interface GHRefreshFooter ()
- @property (strong, nonatomic) UILabel *stateLabel;
- @property (strong, nonatomic) UIActivityIndicatorView *loadingView;
- @property (strong, nonatomic) GHThemeManager *themeManager;
- @end
- @implementation GHRefreshFooter
- - (void)dealloc{
- [self unObserveThemeChange];
- }
- - (instancetype)init {
- self = [super init];
- self.textForIdle = @"上拉即可加载更多...";
- self.textForPulling = @"释放即可加载更多...";
- self.textForRefreshing = @"正在加载...";
- self.textForNoMoreData = @"没有更多了";
- self.themeManager = [[GHThemeManager alloc] init];
- self.backgroundColor = [UIColor clearColor];
- return self;
- }
- /**********************************************************************/
- #pragma mark - OverWrite
- /**********************************************************************/
- - (void)themeChangeAction{
- self.stateLabel.configText = @"T2";
-
- if (self.themeManager.themeType == ThemeType_Night) {
- self.loadingView.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhite;
- }else{
- self.loadingView.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray;
- }
- }
- /**********************************************************************/
- #pragma mark - Private
- /**********************************************************************/
- - (void)prepare {
- [super prepare];
- self.mj_h = 50;
- self.triggerAutomaticallyRefreshPercent = 0.0f;
-
-
- if (self.stateLabel == nil) {
- self.stateLabel = [[UILabel alloc] init];
- self.stateLabel.textAlignment = NSTextAlignmentCenter;
- self.stateLabel.font = [UIFont boldSystemFontOfSize:11];
- self.stateLabel.backgroundColor = [UIColor clearColor];
- [self addSubview:self.stateLabel];
- }
-
- if (self.loadingView == nil) {
- self.loadingView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
- [self addSubview:self.loadingView];
- }
-
- [self themeChangeAction];
- [self observeThemeChange];
- }
- - (void)placeSubviews {
- [super placeSubviews];
- self.stateLabel.frame = self.bounds;
- self.loadingView.center = CGPointMake(self.mj_w * 0.5, self.mj_h * 0.5);
- }
- #pragma mark 监听控件的刷新状态
- - (void)setState:(MJRefreshState)state {
- MJRefreshCheckState;
-
- switch (state) {
- case MJRefreshStateIdle:{
- self.stateLabel.hidden = NO;
- self.stateLabel.text = self.textForIdle;
- [self.loadingView stopAnimating];
- }break;
- case MJRefreshStatePulling:{
- self.stateLabel.hidden = NO;
- self.stateLabel.text = self.textForPulling;
- [self.loadingView stopAnimating];
- }break;
- case MJRefreshStateRefreshing:{
- self.stateLabel.hidden = YES;
- self.stateLabel.text = self.textForRefreshing;
- [self.loadingView startAnimating];
- }break;
- case MJRefreshStateNoMoreData:{
- self.stateLabel.hidden = NO;
- self.stateLabel.text = self.textForNoMoreData;
- [self.loadingView stopAnimating];
- }break;
- default:break;
- }
- self.stateLabel.textColor = RGB(194, 194, 194);
- }
- @end
|