您的位置:首页 > 其它

tableView 头部添加状态 今日头条刷新数据效果

2017-05-26 10:51 786 查看
有的APP如今日头条 在刷新了之后在列表头会出现一条 已经刷新n条数据的提示,,或者是断开网络连接的提示,,出现和消失提示的时候列表会跟着移动,,这里写了个类似的实现,,原理是给tableview 添加头视图,,实现很简单,,如果你的列表有头视图做轮播图,,想用这个方法,,建议把轮播放进cell里实现。。如果不想用cell实现轮播图的话。。那就不用往下看啦。。。。



创建一对HeadTipTool 文件,,继承于NSObject

HeadTipTool.h 文件中 写一个接口

#import <UIKit/UIKit.h>

@interface HeadTip : NSObject

/// tableview 要添加提示的列表tableview

/// tishi 自定义要提示的文字内容

/// time 提示条停留的时间

/// height 提示条的高度

/// textColor 提示文字的颜色

/// backgroundColor 提示框背景颜色

/// font 提示文字的大小

+ (void)addHeadTipWithTableView:(UITableView *)tableView withTishi:(NSString
*)tishi withTime:(NSInteger)time tishiHeight:(CGFloat)height textColor:(UIColor *)textColor
backgroundColor:(UIColor *)backgroundColor font:(UIFont *)font;

@end

HeadTipTool.m  文件中 实现接口方法

- (instancetype)init{

    self = [super
init];

    if (self) {

        

    }

    return
self;

}

+ (void)addHeadTipWithTableView:(UITableView *)tableView withTishi:(NSString
*)tishi withTime:(NSInteger)time tishiHeight:(CGFloat)height textColor:(UIColor *)textColor
backgroundColor:(UIColor *)backgroundColor font:(UIFont *)font{

    UILabel *headLabel = [[UILabel
alloc] initWithFrame:CGRectMake(0,
0, [UIScreen
mainScreen].bounds.size.width,
0)];

    [UIView
animateWithDuration:0.5
animations:^{

        headLabel.frame =
CGRectMake(0,
0, [UIScreen
mainScreen].bounds.size.width,
height);

        tableView.tableHeaderView = headLabel;

    }];

    headLabel.textColor = textColor;

    headLabel.backgroundColor = backgroundColor;

    headLabel.font = font;

    headLabel.textAlignment =
NSTextAlignmentCenter;

    headLabel.text = tishi;

    dispatch_time_t delayTime =
dispatch_time(DISPATCH_TIME_NOW, (int64_t)(time/*延迟执行时间*/
* NSEC_PER_SEC));

    dispatch_after(delayTime,
dispatch_get_main_queue(), ^{

       [UIView
animateWithDuration:0.5
animations:^{

           headLabel.frame =
CGRectMake(0,
0, [UIScreen
mainScreen].bounds.size.width,
0);

            tableView.tableHeaderView = headLabel;

       }completion:^(BOOL finished) {

           tableView.tableHeaderView =
nil;

       }];

    });

}
调用方法,, 可以用于下拉刷新 结束刷新的时候调用,,也可以在断网的时候调用提示。。

需要使用的controller 

#import "HeadTipTool.h"

   [HeadTip
addHeadTipWithTableView:self.listTableView
withTishi:@"请检查网络连接"
withTime:2
tishiHeight:30
textColor:[UIColor
blueColor]
backgroundColor:[UIColor
yellowColor]
font:[UIFont
systemFontOfSize:12]];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐