iOS UITableView去掉多余表格线,tableView去掉表头空白、改变导航栏背景色和标题属性
2017-09-30 15:45
543 查看
转自:http://blog.csdn.net/tuwanli125/article/details/50497403
你的用来显示更多数据的UITableView会出现这种情况吗?比如tableView有多余表格线,tableView表头有空白区域,修改导航栏背景色和标题颜色、字体大小
一、你使用的表的类型是普通表:
UITableViewStylePlain
![](http://img.blog.csdn.net/20160111153804949?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
如果数据量比较少,而你的UITableView的高度是屏幕的高度,就会有很多没用的表格线,这种情况下这样就会没有多余表格线了
加上这句
_tableView.tableFooterView = [[UIViewalloc]initWithFrame:CGRectZero];
效果是这个样子的
![](http://img.blog.csdn.net/20160111154244671?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
一、你使用的表的类型是分组表:
UITableViewStyleGrouped
有没有出现过下面的这种情况
![](http://img.blog.csdn.net/20160111154445361?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
发现上面有一段空白,加上这句就ok了
_tableView.tableHeaderView = [[UIViewalloc]initWithFrame:CGRectMake(0,0,0,0.01)];
分段的tableView去掉段头段位
_tableView.sectionFooterHeight = 0;
_tableView.sectionHeaderHeight = 0;
效果是这样的:
![](http://img.blog.csdn.net/20160111154711037?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
主要的问题倒是已经解决了,如果你需要的话继续看下,如果你想分割线从界面头开始,就要这样写
//分割线顶头显示
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];
}
}
效果是这样式的
![](http://img.blog.csdn.net/20160111155346181?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
附加一点知识就是改变导航栏的属性
//设置导航栏背景
[self.navigationController.navigationBarsetBackgroundImage:[UIImageimageNamed:@"title.png"]forBarMetrics:UIBarMetricsDefault];
//设置导航栏字体属性
NSDictionary *dict =@{NSForegroundColorAttributeName:[UIColorwhiteColor],NSFontAttributeName:[UIFontboldSystemFontOfSize:18]};
[self.navigationController.navigationBarsetTitleTextAttributes:dict];
你的用来显示更多数据的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];
相关文章推荐
- iOS UITableView去掉多余表格线,tableView去掉表头空白、改变导航栏背景色和标题属性
- [Android] 对ImageView设置属性scaleType为FIT_START,如何去掉多余空白
- 去掉tableView多余的空白行分割线
- [Android] 对ImageView设置属性scaleType为FIT_START,如何去掉多余空白
- <学习html>第五天笔记-表格table(创建表格、表格属性、表头标签、表格结构、表格标题标签、合并单元格)
- [Android] 对ImageView设置属性scaleType为FIT_START,如何去掉多余空白
- ios tableView那些事(四)tableView添加标题,头尾和改变cell的宽度
- tableview去掉多余的横线
- HTML表格标记教程(36):表头的背景色属性BGCOLOR
- iOS开发技巧-tableView去掉多余的空行分割线,自定义Cell分割线
- UITableView那些事(四)tableView添加标题,头尾和改变cell的宽度
- iOS tableView去掉显示多余的cell分割线
- iOS 改变tableview cell的背景色
- 如何去掉tableView多余分割线
- jsp制作复合表头并循环产生表格内容,控制隔行变色、鼠标经过改变背景色等操作
- tableview去掉多余的横线
- 去掉UITableView多余的空白行分割线
- tableview--Grouped 模式 去掉 顶部空白
- 使用Masonry动态设置tableview表头---tableHeaderView(解决表头背景色设置不了问题)
- 去掉多余的tableview line