iOS UITableView去掉多余表格线,tableView去掉表头空白、改变导航栏背景色和标题属性

你的用来显示更多数据的UITableView会出现这种情况吗?比如tableView有多余表格线,tableView表头有空白区域,修改导航栏背景色和标题颜色、字体大小

一、你使用的表的类型是普通表:

UITableViewStylePlain


如果数据量比较少,而你的UITableView的高度是屏幕的高度,就会有很多没用的表格线,这种情况下这样就会没有多余表格线了

加上这句

_tableView.tableFooterView = [[UIViewalloc]initWithFrame:CGRectZero];

效果是这个样子的


一、你使用的表的类型是分组表:

UITableViewStyleGrouped

有没有出现过下面的这种情况


发现上面有一段空白,加上这句就ok了

_tableView.tableHeaderView = [[UIViewalloc]initWithFrame:CGRectMake(0,0,0,0.01)];

分段的tableView去掉段头段位

_tableView.sectionFooterHeight = 0;

_tableView.sectionHeaderHeight = 0;

效果是这样的:


主要的问题倒是已经解决了,如果你需要的话继续看下,如果你想分割线从界面头开始,就要这样写

 //分割线顶头显示

   if ([_tableViewrespondsToSelector:@selector(setSeparatorInset:)]) {

        [_tableViewsetSeparatorInset:UIEdgeInsetsMake(0,0,0,0)];

    }

    

   if ([_tableViewrespondsToSelector:@selector(setLayoutMargins:)]) {

        [_tableViewsetLayoutMargins:UIEdgeInsetsMake(0,0,0,0)];

    }

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath

{

   if ([cellrespondsToSelector:@selector(setSeparatorInset:)]) {

        [cellsetSeparatorInset:UIEdgeInsetsZero];

    }

    

   if ([cellrespondsToSelector:@selector(setLayoutMargins:)]) {

        [cellsetLayoutMargins:UIEdgeInsetsZero];

    }

}

效果是这样式的


附加一点知识就是改变导航栏的属性

//设置导航栏背景

    [self.navigationController.navigationBarsetBackgroundImage:[UIImageimageNamed:@"title.png"]forBarMetrics:UIBarMetricsDefault];

    //设置导航栏字体属性

    NSDictionary *dict =@{NSForegroundColorAttributeName:[UIColorwhiteColor],NSFontAttributeName:[UIFontboldSystemFontOfSize:18]};

    [self.navigationController.navigationBarsetTitleTextAttributes:dict];



发布了26 篇原创文章 · 获赞 5 · 访问量 6万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章