去除tableView底部分割线和顶部header

很多时候,会发现写UI也是很麻烦的一件事儿,比如你写一个tableview,不分页的,多余出来的底部非cell部分可能会出现分割线,可以设置为footerView,用 setTableViewFootView

//zhangqing  去除底部分割线
- (void)setExtraCellLineHidden: (UITableView *)tableView{
    UIView *view=[[UIView alloc]initWithFrame:CGRectMake(0, 350, SCREEN_WIDTH, SCREEN_HEIGHT-350-44)];
    view.backgroundColor=KVIEW_Background_Color;
    [tableView setTableFooterView:view];
    [view release];
}
在有section的时候,滑动时官方默认的是section的view不会向上推出屏幕,而是保留在顶部,这样影响体验,可以把第一个section设置为headerView或者自己加一个headerView,然后第0个section的高度设置为0

//zhangqing  只有iphone才有
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section==0) {
        return 0;
    }else if(section==1){
        return 35;
    }else return 0;
}

//zhangqing  只有iphone才有
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    if (section==0) {
        CGRect headerFrame = {{0,0},{320,0}};
        UIView *header = [[[UIView alloc] initWithFrame:headerFrame] autorelease];
        return header;
    }else{
        UIView *searchHistoryHeaderView=[[[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 35)]autorelease];
        UILabel *searchHistoryText=[[UILabel alloc]initWithFrame:CGRectMake(13, 0, 70, 35)];
        [searchHistoryText setText:@"历史记录:"];
        searchHistoryText.font=[UIFont systemFontOfSize:15];
        UIButton *clearnAllBtn = CreateButton(self, @"", @"clearnAllTapped:");
        [clearnAllBtn.titleLabel setFont:KDJFont(15.0f)];
        clearnAllBtn.titleLabel.textAlignment=NSTextAlignmentCenter;
        clearnAllBtn.frameWidth=45;
        clearnAllBtn.frameHeight=23;
        clearnAllBtn.frameY=6;
        clearnAllBtn.frameX=SCREEN_WIDTH-45;
        [clearnAllBtn setImage:PNG_FROM_NAME(@"delAllHistory.png") forState:UIControlStateNormal];
        [clearnAllBtn setImage:PNG_FROM_NAME(@"delAllHistory.png") forState:UIControlStateHighlighted];
        [clearnAllBtn setImageEdgeInsets:UIEdgeInsetsMake(0, 9, 0, 13)];
        [clearnAllBtn setTitleColor:colorWithHexString(@"0072ff") forState:UIControlStateHighlighted];
        [clearnAllBtn setTitleColor:colorWithHexString(@"0072ff") forState:UIControlStateNormal];
        UIView *sepLineHistory=[[UIView alloc]initWithFrame:CGRectMake(0, 34.5, SCREEN_WIDTH, 0.5)];
        [sepLineHistory setBackgroundColor:[UIColor lightGrayColor]];
        [searchHistoryHeaderView addSubview:sepLineHistory];
        [searchHistoryHeaderView addSubview:searchHistoryText];
        [searchHistoryHeaderView addSubview:clearnAllBtn];
        [searchHistoryHeaderView setBackgroundColor:KVIEW_Background_Color];
        [searchHistoryText release];
        [sepLineHistory release];
        return searchHistoryHeaderView;
    }
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值