UITableView常用设置

1. 设置分割线长度为屏幕宽度

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {
        [_tableView setLayoutMargins:UIEdgeInsetsZero];
    }
    else if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0){
        [_tableView setSeparatorInset:UIEdgeInsetsZero];
    }

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {
        [cell setSeparatorInset:UIEdgeInsetsZero];
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
    else if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0){
        [cell setSeparatorInset:UIEdgeInsetsZero];
    }
}

2. 隐藏UITableView的滚动条以及修改滚动条的颜色

(1)隐藏

self.tableView.showsVerticalScrollIndicator = NO;

(2)修改颜色

self.tableView.indicatorStyle=UIScrollViewIndicatorStyleWhite;

3.设置没有内容的单元格不显示

_tableView.tableFooterView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];

4.设置sectionheader自定义字体和颜色

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *customView = [[[UIView alloc] initWithFrame:CGRectMake(10, 0, 300, 44)] autorelease];
    UILabel *headerLabel = [[[UILabel alloc] initWithFrame:CGRectZero] autorelease];
    headerLabel.backgroundColor = [UIColor clearColor];
    headerLabel.textColor = [UIColor lightGrayColor];
    headerLabel.font = [UIFont systemFontOfSize:14.0];
    headerLabel.frame = CGRectMake(10, 0, 300, 44);
    if (section == 0) {
        headerLabel.text = NSLocalizedString(@"GroupName", @"群组名称");
    }
    else if (section == 1){
        headerLabel.text = NSLocalizedString(@"GroupDescription", @"群组公告(0~36)");
    }
    [customView addSubview:headerLabel];
    return customView;
}

5.设置cell里面的字体不会有小部分超出view

cell.contentView.clipsToBounds = YES;
cell.clipsToBounds = YES;

6.当TableView点击的时候,去除点击的阴影

我们在点击UITableView 的cell时,会出现阴影,如不做处理,就会一直显示,怎么样让它点击之后就消失呢?只要重写UITableView的代理方法,就可以解决,方式如下:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    //当手指离开某行时,就让某行的选中状态消失
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

7.设置分割线距周围的距离

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
        //分别为top, left, bottom,right
        cell.separatorInset = UIEdgeInsetsMake(0, 10, 0, 0);
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值