簡體   English   中英

刪除UITableView中2節之間的標題空間

[英]Remove header space between 2 section in the UITableView

我使用此代碼為表視圖節標題設置顏色等

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    // create the parent view that will hold header Label
    UIView* customView = [[UIView alloc] initWithFrame:CGRectMake(10.0, 0.0, 300.0, 44.0)];
    // create the button object
    UILabel * headerLabel = [[UILabel alloc] initWithFrame:CGRectZero];
    headerLabel.backgroundColor = [UIColor clearColor];
    headerLabel.opaque = NO;
    headerLabel.textColor = [UIColor whiteColor];
    headerLabel.highlightedTextColor = [UIColor whiteColor];
    headerLabel.font = [UIFont boldSystemFontOfSize:18];
    headerLabel.shadowColor = [UIColor blackColor];
    headerLabel.shadowOffset = CGSizeMake(0, 1.0);
    headerLabel.frame = CGRectMake(10.0, 0.0, 300.0, 44.0);

    if (section == 0) {

        headerLabel.text = @"Section 0 header";
        [customView addSubview:headerLabel];
    }
    if (section == 1) {

        //headerLabel.text = @"Section 1 header";
        //[customView addSubview:headerLabel];
        customView = nil;
        tableView.tableHeaderView = nil;
    }
    if (section == 2) {

        headerLabel.text = @"Section 2 header";
        [customView addSubview:headerLabel];
    }

    return customView;
}

在第1節中,我不需要標題,但第0節和第1節之間仍有更大的空間。

在此輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM