美文网首页
类似今日头条的刷新推荐提示

类似今日头条的刷新推荐提示

作者: 书写不简单 | 来源:发表于2018-12-27 12:20 被阅读0次

实现很简单,废话不多说:

.h 文件中声明

/**
 * 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;

.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;
            
        }];
        
    });
    
}

截图:


example.png

相关文章

网友评论

      本文标题:类似今日头条的刷新推荐提示

      本文链接:https://www.haomeiwen.com/subject/budrlqtx.html