博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
去掉UItableview headerview黏性(sticky)
阅读量:5232 次
发布时间:2019-06-14

本文共 4173 字,大约阅读时间需要 13 分钟。

#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);     } }

 

转载于:https://www.cnblogs.com/allanliu/p/4425407.html

你可能感兴趣的文章
Silverlight 的菜单控件。(不是 Toolkit的)
查看>>
:hover 鼠标同时触发两个元素变化
查看>>
go语言学习十三 - 相等性
查看>>
Idea 提交代码到码云(提交到github也大同小异)
查看>>
c#连接excel2007未安装ISAM解决
查看>>
Mono 异步加载数据更新主线程
查看>>
初识lua
查看>>
我是插件狂人,jDuang,jValidator,jModal,jGallery
查看>>
张季跃 201771010139《面向对象程序设计(java)》第四周学习总结
查看>>
如何解除循环引用
查看>>
android中fragment的使用及与activity之间的通信
查看>>
jquery的contains方法
查看>>
python3--算法基础:二分查找/折半查找
查看>>
Perl IO:随机读写文件
查看>>
Perl IO:IO重定向
查看>>
转:基于用户投票的排名算法系列
查看>>
WSDL 详解
查看>>
[转]ASP数组全集,多维数组和一维数组
查看>>
C# winform DataGridView 常见属性
查看>>
逻辑运算和while循环.
查看>>