TableView的tableHeaderView表头自适应(表头Masonry)
来源:互联网 发布:淘宝看买家退货率 编辑:程序博客网 时间:2024/05/16 10:30
#import "OrderCheckLogisticsPathViewController.h"
#import "ConstantHeader.h"
#import <Masonry/Masonry.h>
#import "MBProgressHUD+QSJ.h"
#import "AlertUtil.h"
#import "MJRefresh.h"
#import "UIColor+RCColor.h"
#import "UIImageView+WebCache.h"
#import "OrderLogisticsFirstPathCell.h"
#import "OrderLogisticsPathCell.h"
@interface OrderCheckLogisticsPathViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong)UITableView *myTableView;
@property(nonatomic,strong)UILabel *wuLiuState ,*wuLiuCom ,*wuLiuNum ,*wuLiuTel;
@property(nonatomic,strong)UIImageView *wuLiuImgv;
@end
@implementation OrderCheckLogisticsPathViewController
- (void)viewDidLoad {
[superviewDidLoad];
self.title =@"查看物流";
//绘画添加tableview
self.myTableView = [[UITableViewalloc]initWithFrame:CGRectMake(0,0, SCREEN_SIZE_WIDTH,SCREEN_SIZE_WIDTH) style:UITableViewStyleGrouped];
self.myTableView.delegate =self;
self.myTableView.dataSource =self;
self.myTableView.rowHeight =UITableViewAutomaticDimension;
self.myTableView.estimatedRowHeight =55;
self.myTableView.showsVerticalScrollIndicator =NO;
self.myTableView.showsHorizontalScrollIndicator =NO;
self.myTableView.backgroundColor =NORMAL_BKG_GREY;
[self.viewaddSubview:self.myTableView];
[self.myTableViewmas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.view);
make.left.mas_equalTo(self.view);
make.right.mas_equalTo(self.view);
make.bottom.mas_equalTo(self.view);
}];
[self.myTableViewregisterClass:[OrderLogisticsFirstPathCellclass] forCellReuseIdentifier:@"OrderLogisticsFirstPathCell"];
[self.myTableViewregisterClass:[OrderLogisticsPathCellclass] forCellReuseIdentifier:@"OrderLogisticsPathCell"];
self.myTableView.separatorStyle =UITableViewCellSeparatorStyleNone;
//头视图
//1.原理初始化一个view(headerView) 临时加到Self.view上或者其他固定地方
//实际上是 headerView.frame = CGRectMake(0, 0, SCREEN_WIDTH, 155);
UIView *headerView = [[UIViewalloc]initWithFrame:CGRectMake(0,0, SCREEN_WIDTH,100)];
headerView.backgroundColor =NORMAL_BKG_GREY;
[self.viewaddSubview:headerView];
//2.绘图
//上
UIView *shangView = [[UIViewalloc]init];
shangView.backgroundColor = [UIColorwhiteColor];
[headerView addSubview:shangView];
[shangView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(headerView.mas_top);
make.left.right.mas_equalTo(headerView);
make.height.mas_equalTo(105);
}];
self.wuLiuImgv = [[UIImageViewalloc]init];
[shangView addSubview:self.wuLiuImgv];
[self.wuLiuImgvmas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(shangView.mas_top).mas_offset(TEXT_LINE_DISTANCE);
make.left.mas_equalTo(shangView.mas_left).mas_equalTo(TEXT_LINE_DISTANCE);
make.size.mas_equalTo(CGSizeMake(90,90));
}];
[self.wuLiuImgvsd_setImageWithURL:[NSURLURLWithString:@""]placeholderImage:[UIImageimageNamed:@"placeholder_img"]];
//物流状态
UILabel *wlState = [[UILabelalloc]init];
[shangView addSubview:wlState];
wlState.textColor =TEXT_DARK_GREY;
wlState.font =NORMAL_FONT;
wlState.text =@"物流状态:";
[wlState mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.wuLiuImgv.mas_top);
make.left.mas_equalTo(self.wuLiuImgv.mas_right).mas_offset(TEXT_EDGE_DISTANCE);
}];
self.wuLiuState = [[UILabelalloc]init];
[shangView addSubview:self.wuLiuState];
self.wuLiuState.textColor = [UIColorcolorWithHexString:@"#fd7191"alpha:1.0];
self.wuLiuState.font =NORMAL_FONT;
self.wuLiuState.text =@"运输中";
[self.wuLiuStatemas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(wlState.mas_top);
make.left.mas_equalTo(wlState.mas_right).mas_offset(TEXT_LINE_DISTANCE);
}];
//什么快递
UILabel *wlCom = [[UILabelalloc]init];
[shangView addSubview:wlCom];
wlCom.textColor =TEXT_LIGHT_GREY;
wlCom.font =MIDDLE_SECOND_FONT;
wlCom.text =@"承运来源:";
[wlCom mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(wlState.mas_bottom).mas_offset(TEXT_LINE_DISTANCE);
make.left.mas_equalTo(self.wuLiuImgv.mas_right).mas_offset(TEXT_EDGE_DISTANCE);
}];
self.wuLiuCom = [[UILabelalloc]init];
[shangView addSubview:self.wuLiuCom];
self.wuLiuCom.textColor =TEXT_LIGHT_GREY;
self.wuLiuCom.font =MIDDLE_SECOND_FONT;
self.wuLiuCom.text =@"韵达快递";
[self.wuLiuCommas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(wlCom.mas_top);
make.left.mas_equalTo(wlCom.mas_right).mas_offset(TEXT_LINE_DISTANCE);
}];
//订单编号
UILabel *wlNum = [[UILabelalloc]init];
[shangView addSubview:wlNum];
wlNum.textColor =TEXT_LIGHT_GREY;
wlNum.font =MIDDLE_SECOND_FONT;
wlNum.text =@"订单编号:";
[wlNum mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(wlCom.mas_bottom).mas_offset(TEXT_LINE_DISTANCE);
make.left.mas_equalTo(self.wuLiuImgv.mas_right).mas_offset(TEXT_EDGE_DISTANCE);
}];
self.wuLiuNum= [[UILabelalloc]init];
[shangView addSubview:self.wuLiuNum];
self.wuLiuNum.textColor =TEXT_LIGHT_GREY;
self.wuLiuNum.font =MIDDLE_SECOND_FONT;
self.wuLiuNum.text =@"204956123454343";
[self.wuLiuNummas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(wlNum.mas_top);
make.left.mas_equalTo(wlNum.mas_right).mas_offset(TEXT_LINE_DISTANCE);
}];
//官方电话
UILabel *wlTel = [[UILabelalloc]init];
[shangView addSubview:wlTel];
wlTel.textColor =TEXT_LIGHT_GREY;
wlTel.font =MIDDLE_SECOND_FONT;
wlTel.text =@"官方电话:";
[wlTel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(wlNum.mas_bottom).mas_offset(TEXT_LINE_DISTANCE);
make.left.mas_equalTo(self.wuLiuImgv.mas_right).mas_offset(TEXT_EDGE_DISTANCE);
}];
self.wuLiuTel= [[UILabelalloc]init];
[shangView addSubview:self.wuLiuTel];
self.wuLiuTel.textColor = [UIColorcolorWithHexString:@"#2b98de"alpha:1.0];
self.wuLiuTel.font =MIDDLE_SECOND_FONT;
self.wuLiuTel.text =@"204956";
[self.wuLiuTelmas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(wlTel.mas_top);
make.left.mas_equalTo(wlTel.mas_right).mas_offset(TEXT_LINE_DISTANCE);
}];
[shangView mas_remakeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(headerView.mas_top);
make.left.right.mas_equalTo(headerView);
make.bottom.mas_equalTo(self.wuLiuImgv.mas_bottom).mas_offset(TEXT_LINE_DISTANCE);
}];
//线
UIView *lineOne = [[UIViewalloc]init];
[headerView addSubview:lineOne];
lineOne.backgroundColor =LINE_CELL_COLOR;
[lineOne mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(shangView.mas_bottom);
make.left.right.mas_equalTo(0);
make.height.mas_equalTo(0.5);
}];
//缝隙
UIView *fengVeiw = [[UIViewalloc]init];
[headerView addSubview:fengVeiw];
fengVeiw.backgroundColor =NORMAL_BKG_GREY;
[fengVeiw mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(shangView.mas_bottom);
make.left.right.mas_equalTo(0);
make.height.mas_equalTo(5);
}];
//线
UIView *lineTwo = [[UIViewalloc]init];
[headerView addSubview:lineTwo];
lineTwo.backgroundColor =LINE_CELL_COLOR;
[lineTwo mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(fengVeiw.mas_bottom);
make.left.right.mas_equalTo(0);
make.height.mas_equalTo(0.5);
}];
//下面标题菜鸟果果
UIView *xiaBkgView = [[UIViewalloc]init];
[headerView addSubview:xiaBkgView];
xiaBkgView.backgroundColor = [UIColorwhiteColor];
[xiaBkgView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(lineTwo.mas_bottom);
make.left.right.mas_equalTo(0);
make.height.mas_equalTo(43);
}];
UIImageView *tIconImgv = [[UIImageViewalloc]init];
[xiaBkgView addSubview:tIconImgv];
tIconImgv.layer.cornerRadius =10;
tIconImgv.layer.masksToBounds =YES;
[tIconImgv mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.mas_equalTo(xiaBkgView);
make.left.mas_equalTo(TEXT_EDGE_DISTANCE);
make.size.mas_equalTo(CGSizeMake(20,20));
}];
[tIconImgv sd_setImageWithURL:[NSURLURLWithString:@""]placeholderImage:[UIImageimageNamed:@"chatListCellHead"]];
//菜鸟果果文本
UILabel *cnTextL = [[UILabelalloc]init];
[xiaBkgView addSubview:cnTextL];
cnTextL.font =MIDDLE_SECOND_FONT;
NSString *cntext =@"本数据由菜鸟裹裹提供";
NSMutableAttributedString *string = [[NSMutableAttributedStringalloc]initWithString:cntext];
[string addAttributes:@{NSForegroundColorAttributeName:TEXT_DARK_GREY}range:NSMakeRange(0,4)];
[string addAttributes:@{NSForegroundColorAttributeName:[UIColorcolorWithHexString:@"#2b98de"alpha:1.0]}range:NSMakeRange(4,4)];
[string addAttributes:@{NSForegroundColorAttributeName:TEXT_DARK_GREY}range:NSMakeRange(8,2)];
cnTextL.attributedText = string;
[cnTextL mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.mas_equalTo(xiaBkgView);
make.left.mas_equalTo(tIconImgv.mas_right).mas_offset(TEXT_LINE_DISTANCE);
}];
//线
UIView *lineThree = [[UIViewalloc]init];
[headerView addSubview:lineThree];
lineThree.backgroundColor =LINE_CELL_COLOR;
[lineThree mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(xiaBkgView.mas_bottom);
make.left.right.mas_equalTo(0);
make.height.mas_equalTo(0.5);
}];
//3.masonry得到headerview尺寸
[headerView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.myTableView.mas_top);
make.left.right.mas_equalTo(self.myTableView);
make.bottom.mas_equalTo(lineThree);
}];
[headerView layoutSubviews];
//4.适配得到相应高
CGFloat height = [headerViewsystemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
CGRect frame = headerView.frame;
frame.size.height = height;
headerView.frame = frame;
//5.得到表头
self.myTableView.tableHeaderView = headerView;
}
#pragma makr----tableview Delegate DataSource----
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return4;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
//Buyer seller
switch (indexPath.row) {
case0:
{
OrderLogisticsFirstPathCell *cell = [tableViewdequeueReusableCellWithIdentifier:@"OrderLogisticsFirstPathCell"];
cell.selectionStyle =UITableViewCellSelectionStyleNone;
return cell;
}
break;
case1:
{
OrderLogisticsPathCell *cell = [tableViewdequeueReusableCellWithIdentifier:@"OrderLogisticsPathCell"];
cell.selectionStyle =UITableViewCellSelectionStyleNone;
return cell;
}
break;
case2:
{
OrderLogisticsPathCell *cell = [tableViewdequeueReusableCellWithIdentifier:@"OrderLogisticsPathCell"];
cell.selectionStyle =UITableViewCellSelectionStyleNone;
return cell;
}
break;
case3:
{
OrderLogisticsPathCell *cell = [tableViewdequeueReusableCellWithIdentifier:@"OrderLogisticsPathCell"];
cell.selectionStyle =UITableViewCellSelectionStyleNone;
return cell;
}
break;
default:
{
OrderLogisticsPathCell *cell = [tableViewdequeueReusableCellWithIdentifier:@"OrderLogisticsPathCell"];
cell.selectionStyle =UITableViewCellSelectionStyleNone;
return cell;
}
break;
}
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return0.00001;
}
-(void)viewWillAppear:(BOOL)animated{
[superviewWillAppear:animated];
self.tabBarController.tabBar.hidden = YES;
}
- (void)didReceiveMemoryWarning {
[superdidReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- TableView的tableHeaderView表头自适应(表头Masonry)
- 使用Masonry动态设置tableview表头---tableHeaderView(解决表头背景色设置不了问题)
- tableView的表头
- tableHeaderView的Masonry
- tableview添加表头
- UITableView的表头表尾(tableHeaderView,tableFooterView) 和 组头组尾(viewForHeaderInSection,heightForFooterInSec
- TableView 下拉放大表头图片
- tableview下拉 表头缩放效果
- 让UITableView的表头随着tableView一起滚动
- 让UITableView的表头随着tableView一起滚动
- table 表头斜线canvas 自适应
- table 表头斜线 canvas自适应
- TableView之表头、表尾,区头、区尾!
- QTreeView设置字体大小和表头自适应
- 固定表头的CSS
- 可编辑的表头
- 固定表头的DataGrid
- GridView表头的使用
- java自带线程池和队列详细讲解
- 使用Dom4j进行XML解析
- Android7.0 PowerManagerService(4) Power按键流程
- iOS10 适配、Xcode8配置总结
- 【MySQL】20个经典面试题,全部答对月薪10k+
- TableView的tableHeaderView表头自适应(表头Masonry)
- jquery设置下拉框selected不起作用
- js 实现拖拽
- IPMI学习
- 什么是weight和weightSum
- 【工具】IAR编译出错警告详解
- cdn加速与ssl加速
- 实战CoordinatorLayout+Toolbar,CoordinatorLayout+CollapsingToolbarLayout
- MTK PerfService(2)--PerfService的落地