• 去掉UItableview headerview黏性(sticky)


    #pragma mark - UICollectionViewDelegates for photos
    - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
        
        UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, Main_Screen_Width, 50)];
        headerView.backgroundColor=[UIColor clearColor];
        
        //替换
        UIView *circleView = [[UIView alloc]initWithFrame:CGRectMake(Main_Screen_Width*0.05, 10, 250, 30)];
        [circleView setBackgroundColor:[UIColor clearColor]];
        [headerView addSubview:circleView];
        
        
        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
        [dateFormatter setDateFormat:@"yyyy-MM-dd"];
        NSDate *date = [dateFormatter dateFromString:[newDateArray objectAtIndex:section]];
        
        
        NSDate *today = [NSDate date];
        NSString *strWeek = [NDDateTools getWeekdayFromNSDate:date];
        
        UIFont *myCustomFont1 = [UIFont fontWithName:@"Avenir-Light" size:22];
        UIFont *myCustomFont2 = [UIFont fontWithName:@"Avenir-Light" size:14];
        UIFont *myCustomFont3 = [UIFont fontWithName:@"Avenir-Light" size:16];
        
        int compare = [NDDateTools compareOneDay:today withAnotherDay:date];
        CGFloat topPadding = 10.0f;
        if (compare == 0) {
            UILabel *todayLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, topPadding, 50, 20)];
            todayLabel.text=  @"今天";
            todayLabel.font = myCustomFont1;
            todayLabel.backgroundColor = [UIColor clearColor];
            todayLabel.textAlignment = NSTextAlignmentLeft;
            todayLabel.textColor=RGBCOLOR(98, 98, 98);
            [circleView addSubview:todayLabel];
            
            UILabel *dayLabel = [[UILabel alloc] initWithFrame:CGRectMake(todayLabel.frame.size.width, topPadding+5, 80, 20)];
            NSString *strDay1 = [dateFormatter stringFromDate:date];
            dayLabel.text=  strDay1;
            dayLabel.font = myCustomFont2;
            dayLabel.backgroundColor = [UIColor clearColor];
            dayLabel.textAlignment = NSTextAlignmentCenter;
            dayLabel.textColor=RGBCOLOR(137, 137, 137);
            [circleView addSubview:dayLabel];
            
            UILabel *weekDayLabel = [[UILabel alloc] initWithFrame:CGRectMake(todayLabel.frame.size.width+dayLabel.frame.size.width, topPadding+5, 50, 20)];
            weekDayLabel.text= [NSString stringWithFormat:@"(%@)",strWeek];
            weekDayLabel.font = myCustomFont2;
            weekDayLabel.backgroundColor = [UIColor clearColor];
            weekDayLabel.textColor=RGBCOLOR(137, 137, 137);
            weekDayLabel.textAlignment = NSTextAlignmentCenter;
            [circleView addSubview:weekDayLabel];
        }else{
            
            UILabel *dayLabel = [[UILabel alloc] initWithFrame:CGRectMake(0,topPadding, 120, 20)];
            NSString *strDay = [dateFormatter stringFromDate:date];
            dayLabel.text=  strDay;
            dayLabel.font = myCustomFont1;
            dayLabel.backgroundColor = [UIColor clearColor];
            dayLabel.textAlignment = NSTextAlignmentLeft;
            dayLabel.textColor=RGBCOLOR(98, 98, 98);
            [circleView addSubview:dayLabel];
            
            UILabel *weekDayLabel = [[UILabel alloc] initWithFrame:CGRectMake(dayLabel.frame.size.width,topPadding, 50, 25)];
            weekDayLabel.text= [NSString stringWithFormat:@"(%@)",strWeek];
            weekDayLabel.font = myCustomFont3;
            weekDayLabel.backgroundColor = [UIColor clearColor];
            weekDayLabel.textColor=RGBCOLOR(137, 137, 137);
            weekDayLabel.textAlignment = NSTextAlignmentLeft;
            [circleView addSubview:weekDayLabel];
        }
        
        return headerView;
    }

    - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
        return 50.0;
    }


    //去掉UItableview headerview黏性(sticky)
    - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
        CGFloat sectionHeaderHeight = 50;
        if (scrollView.contentOffset.y<=sectionHeaderHeight&&scrollView.contentOffset.y>=0) {
            scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0);
        } else if (scrollView.contentOffset.y>=sectionHeaderHeight) {
            scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0);
        }
    }

  • 相关阅读:
    Webstorm常用快捷键
    微信内置浏览器是什么?(复制篇)
    jquery.cookie.js 操作cookie实现记住密码功能的实现代码
    sublime text 3 快捷键大全
    http_load的安装及使用方法
    Mysql压测工具mysqlslap 讲解
    ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
    percona-toolkit工具包的使用教程之开发类工具
    MYSQL管理之主从同步管理
    percona-toolkit系列之介绍和安装(mysql复制工具)
  • 原文地址:https://www.cnblogs.com/allanliu/p/4425407.html
Copyright © 2020-2023  润新知