美文网首页
Demo - TableView第一个section的heade

Demo - TableView第一个section的heade

作者: ___1o_8o | 来源:发表于2016-07-04 14:04 被阅读1066次
    - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
        UIView *headV = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenW, 36)];
        headV.backgroundColor = [UIColor whiteColor];
        UILabel *text = [[UILabel alloc] init];
        text.font = [UIFont systemFontOfSize:15];
        text.textColor = [UIColor blackColor];
        [headV addSubview:text];
        [text mas_makeConstraints:^(MASConstraintMaker *make) {
            make.height.equalTo(@16);
            make.left.equalTo(headV).offset(15);
            make.centerY.equalTo(headV);
            make.width.equalTo(headV).multipliedBy(0.5);
        }];
        UIView *lineV = [[UIView alloc] initWithFrame:CGRectMake(0, 35.5, kScreenW, 0.5)];
        lineV.backgroundColor = [UIColor lightGrayColor];
        lineV.alpha = 0.5;
        [headV addSubview:lineV];
        switch (section) {
            case 0:{
                text.text = @"论坛";
                [self initReloadBtnWithSuperView:headV];
                break;
            }
            case 1:{
                text.text = @"通知";
                break;
            }
            default:
                break;
        }
        return headV;
    }
    
    - (void)initReloadBtnWithSuperView:(UIView *)headV{
        UIButton *reloadBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [reloadBtn setBackgroundImage:[UIImage imageNamed:@"ununited_btn"] forState:UIControlStateNormal];
        [reloadBtn setTitle:@"刷新" forState:UIControlStateNormal];
        reloadBtn.titleLabel.font = [UIFont systemFontOfSize:14];
        [reloadBtn setTitleColor:[UIColor colorWithRed:(30 / 255.0) green:(30 / 255.0) blue:(30 / 255.0) alpha:1.0] forState:UIControlStateNormal];
        [reloadBtn addTarget:self action:@selector(reloadBtnDidClick:) forControlEvents:UIControlEventTouchUpInside];
        [headV addSubview:reloadBtn];
        self.reloadBtn = reloadBtn;
        [reloadBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(50, 24));
            make.centerY.equalTo(headV);
            make.right.equalTo(headV).offset(-20);
        }];
        
        self.indicatorV = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
        [headV addSubview:self.indicatorV];
        [self.indicatorV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.center.equalTo(reloadBtn);
            make.size.mas_equalTo(CGSizeMake(40, 40));
        }];
    }
    
    //刷新按钮点击
    - (void)reloadBtnDidClick:(UIButton *)btn{
        btn.hidden = YES;
        [self.indicatorV startAnimating];
        [self requestNoticeList];
        [self requestPostDirList];
    }
    
    //开始刷新
    - (void)startReload{
        self.reloadBtn.hidden = YES;
        [self.indicatorV startAnimating];
    }
    
    //结束刷新
    - (void)stopReload{
        [self.indicatorV stopAnimating];
        self.reloadBtn.hidden = NO;
    }
    

    相关文章

      网友评论

          本文标题:Demo - TableView第一个section的heade

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