zoukankan      html  css  js  c++  java
  • 去掉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);
        }
    }

  • 相关阅读:
    Vue基础---官网
    echarts 4.0+画全国地图(省 市 区),地图撒点---vue项目中实战
    comeBack
    vue项目知识点汇总
    开发小总结
    Angular ---小demo体验angular项目开发知识点
    Angular ---小demo体验angular项目开发知识点2--angular中的表单验证、路由、路由守卫、http、http拦截器
    TypeScipt介绍
    Angular基础知识---模块、装饰器、组件、如何创建组件、事件处理机制、插值表达式(双括号)
    mybatis传递多个参数的三种方式
  • 原文地址:https://www.cnblogs.com/allanliu/p/4425407.html
Copyright © 2011-2022 走看看