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

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

2017-09-30 15:45 543 查看
转自:http://blog.csdn.net/tuwanli125/article/details/50497403

你的用来显示更多数据的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];

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: