您的位置:首页 > 产品设计 > UI/UE

uitableview group的一些问题 (设置两个section之间的距离,设置背景颜色 等)在plain下去掉foot view的粘性

2014-03-21 12:10 465 查看
1.group 时背景颜色设置

UIView *backview = [[UIView alloc]init];

backview.backgroundColor = [UIColor redColor];

self.tableView.backgroundView = backview;

self.tableView.backgroundColor = [UIColor redColor];

或者直接把backgroundView 设置为nil;

2.在继承UITableViewController下设置tableview 样式

- (id)initWithStyle:(UITableViewStyle)style

{

self = [super initWithStyle:style];

if (self) {

self = [super initWithStyle:UITableViewStyleGrouped];

}

return self;

}

3.设置两个section之间的距离

总之就是通过设置self.tableView.sectionFooterHeight = 0;self.tableView.sectionHeaderHeight = 10; 这两个view的高度来调整section之间的距离

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{

return 20;

}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{

return 20;

}

4.去掉cell边框

其实跟背景设置一样 在group下 他的BackgroundView并不是空 在plain下是空的 只要按照同样方法设置一个他的BackgroundView就可以去掉他的边框了

UIView *backview = [[ UIView alloc]init];

backview.backgroundColor = [UIColor whiteColor];

[cell setBackgroundView:backview];

[cell setBackgroundColor:[UIColor clearColor]];

5.有时候设置 footview(headerview)不要他跟着section 移动即UItableview header(footer)view黏性(sticky)可以使用以下方法设置

a. 设置tableview格式为group 这样是不会跟着滑动的

但是在此种方法下他的headerview 在section=0 的时候 设置header view.height =0 他仍有一个header view 在头部解决方法如下

在- (id)initWithStyle:(UITableViewStyle)style

{

self = [super initWithStyle:style];

if (self) {

self = [super initWithStyle:UITableViewStyleGrouped];

self.tableView.tableHeaderView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, VIEW_WIDTH, 0.01f)];

//设置这个 这个在ios7和以上都可以去掉头部的那个显示 但是在ios 7一下 还要加上 self.tableView.sectionHeaderHeight = 0;

}

return self;

}
然后在-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{

if (section == 0 )

{

return 0;

}

//其他地方需要设置header的地方在另外设置就可以了

else

{

return 10;

}}

b. 在plain下使用以下方法设置

//去掉UItableview headerview黏性(sticky)

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {

CGFloat sectionHeaderHeight = 40;

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

}

}

新手 有啥不对的地方 望指正 谢谢!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: