IOS TableView的下拉刷新与小菊花样本

//_tableView 这个太简单需要的代码篇幅有点多,自己去定义,
//
设置全局变量 UIRefreshControl* refres; //下拉刷新 refres=[[UIRefreshControl alloc]init]; refres.attributedTitle=[[NSAttributedString alloc]initWithString:@"下拉刷新中..."]; [refres addTarget:self action:@selector(refresh) forControlEvents:UIControlEventValueChanged]; [_tableView addSubview:refres];
//上面的代码添加在ViewDidLoad中
//下拉所要触发的事件,刷新逻辑可以写在里面 -(void)refresh{ NSLog(@"刷新修改表"); if (refres.refreshing) { refres.attributedTitle=[[NSAttributedString alloc]initWithString:@"刷新成功"]; [refres endRefreshing]; } }

 小菊花控件

#import <UIKit/UIKit.h>

@interface ActivityViewAction : UIView
{
    UIActivityIndicatorView * _activityV;
    UILabel * _textLabel;
}

//显示文本和小菊花.
-(void)showWithText:(NSString *)showText;


-(void)hidden;

@end



#import "ActivityViewAction.h"

@implementation ActivityViewAction


-(instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame])
    {
        //        背景View  为了防止,用户误操作.
        UIView * backgroundView = [[UIView alloc] initWithFrame:self.bounds];
        backgroundView.backgroundColor = [UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:1];
         
        
        [self addSubview:backgroundView];
        
        UIView * loadingV = [[UIView alloc] initWithFrame:CGRectMake(120, 300, 100, 100)];
        
        loadingV.layer.cornerRadius = 10;
        
        loadingV.backgroundColor = [UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:1];
        
        [self addSubview:loadingV];
        //      小菊花  (考究:它的宽高是多少.37,37)
        _activityV = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
        _activityV.color=[UIColor blackColor];
        _activityV.center = CGPointMake(50, 40);
        
        [loadingV addSubview:_activityV];
        
        
        _textLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 65, 80, 30)];//小菊花下面的文本
        _textLabel.textColor = [UIColor blackColor];
        _textLabel.textAlignment= NSTextAlignmentCenter;
        [loadingV addSubview:_textLabel];
        self.alpha=0;
    }
    return self;
}
//显示调用这个函数
-(void)showWithText:(NSString *)showText
{
    if (self.alpha == 0)//包含了,self.hidden == YES
    {
        self.alpha = 1.0;
        _textLabel.text = showText;
        [_activityV startAnimating];
    }
}
//隐藏调用这个函数
-(void)hidden
{
    self.alpha = 0.0;
    [_activityV stopAnimating];
    _textLabel.text = @"";
}

这个只是大体的样本,具体需求自己添加

原文地址:https://www.cnblogs.com/mojiewei/p/5047529.html