今天来给大家分享一下关于分组样式-样式的问题,以下是对此问题的归纳整理,让我们一起来看看吧。

tableview分组样式每组section之间距离的调整
两个注意点:
1.默认tableview分组样式,每组section有额外头部和尾部间距,如果每组之间的间距一致,可以调整tableview的两个属性sectionHeaderHeight和sectionFooterHeight
2.如果有导航条和tabbar,tableview的内容视图也有自己额外的头部和尾部间距,这两个间距是内边距,是可调整的,内容视图中包含cell控件
要求:
1.tableview的分组样式,每组之间距离很大,特别是第一个cell和导航栏之间的距离,不好看,所以需要调整seciton之间的间距,
2.当UITableView的style为UITableViewStyleGrouped时,section之间默认的距离往往不是我们想要的。那怎么设置呢?我们知道每个section都有自己的header和footer,它们的高度和就是section之间的间距
self.tableView.sectionHeaderHeight = 10;self . table view . section footer height = 10;
则区间距离为20 (10+10),默认为18+18。注意,第一组单元没有头部间距,只有尾部间距。
3.如何调整第一组与导航栏的距离?
分组样式中第一个单元格的默认y值是35。如果间距为10,则必须上移25,但这个移位应该是内容视图的整体移位,tableview的表头内边距要自行调整
。表格视图。content insert = uiedgeinsetsmash(-25,
总结:
如果调整区段之间的距离,两个属性将一起调整;如果整体上移,内边距属性contentInset h/]如何在iOS6中实现TableView的分组样式?
为iOS6实现TableView分组样式:
-(void)tableView:(UITableView*)tableViewwillDisplayCell:(UITableViewCell*)cellforRowAtIndexPath:(NSIndexPath*)indexPath
{
if([cellrespondsToSelector:@selector(tintColor)]){
if(tableView==self.tableView){
CGFloatcornerRadius=5.f;
cell.backgroundColor=UIColor.clearColor;
CAShapeLayer*layer=[[CAShapeLayeralloc]init];
CGMutablePathRefpathRef=CGPathCreateMutable();
CGRectbounds=CGRectInset(cell.bounds,10,0);
BOOLaddLine=NO;
if(indexPath.row==0&&indexPath.row==[tableViewnumberOfRowsInSection:indexPath.section]-1){
CGPathAddRoundedRect(pathRef,nil,bounds,cornerRadius,cornerRadius);
}elseif(indexPath.row==0){
CGPathMoveToPoint(pathRef,nil,CGRectGetMinX(bounds),CGRectGetMaxY(bounds));
CGPathAddArcToPoint(pathRef,nil,CGRectGetMinX(bounds),CGRectGetMinY(bounds),CGRectGetMidX(bounds),CGRectGetMinY(bounds),cornerRadius);
CGPathAddArcToPoint(pathRef,nil,CGRectGetMaxX(bounds),CGRectGetMinY(bounds),CGRectGetMaxX(bounds),CGRectGetMidY(bounds),cornerRadius);
CGPathAddLineToPoint(pathRef,nil,CGRectGetMaxX(bounds),CGRectGetMaxY(bounds));
addLine=YES;
}elseif(indexPath.row==[tableViewnumberOfRowsInSection:indexPath.section]-1){
CGPathMoveToPoint(pathRef,nil,CGRectGetMinX(bounds),CGRectGetMinY(bounds));
CGPathAddArcToPoint(pathRef,nil,CGRectGetMinX(bounds),CGRectGetMaxY(bounds),CGRectGetMidX(bounds),CGRectGetMaxY(bounds),cornerRadius);
CGPathAddArcToPoint(pathRef,nil,CGRectGetMaxX(bounds),CGRectGetMaxY(bounds),CGRectGetMaxX(bounds),CGRectGetMidY(bounds),cornerRadius);
CGPathAddLineToPoint(pathRef,nil,CGRectGetMaxX(bounds),CGRectGetMinY(bounds));
}else{
CGPathAddRect(pathRef,nil,bounds);
addLine=YES;
}
layer.path=pathRef;
CFRelease(pathRef);
layer.fillColor=[UIColorcolorWithWhite:1.falpha:0.8f].CGColor;
if(addLine==YES){
CALayer*lineLayer=[[CALayeralloc]init];
CGFloatlineHeight=(1.f/[UIScreenmainScreen].scale);
lineLayer.frame=CGRectMake(CGRectGetMinX(bounds)+10,bounds.size.height-lineHeight,bounds.size.width-10,lineHeight);
lineLayer.backgroundColor=tableView.separatorColor.CGColor;
[layeraddSublayer:lineLayer];
}
UIView*testView=[[UIViewalloc]initWithFrame:bounds];
[testView.layerinsertSublayer:layeratIndex:0];
testView.backgroundColor=UIColor.clearColor;
cell.backgroundView=testView;
}
}}
以上就是由优质生活领域创作者 嘉文社百科网小编 整理编辑的,如果觉得有帮助欢迎收藏转发~
本文地址:https://www.jwshe.com/1226022.html,转载请说明来源于:嘉文社百科网
声明:本站部分文章来自网络,如无特殊说明或标注,均为本站原创发布。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。分享目的仅供大家学习与参考,不代表本站立场。