【问题标题】:Change the footer size for only one section in the UITableView仅更改 UITableView 中一个部分的页脚大小
【发布时间】:2014-04-12 12:37:12
【问题描述】:

我有一个分组的静态UITableView,其中 4 个部分。在所有 4 个部分中,我都有一个页眉,只有最后一个部分有一个页脚(代表应用程序的版本)。

因为我已经使用Interface Builder 和Storyboard 建立了我的UITableViewController,所以我可以在检查器中设置页眉和页脚边距的大小,因此我将每个设置为10。

我面临的问题是,由于检查器中的页脚大小,代表页脚的 UILabel 被截断。

我正在使用自定义标签,因为我将页脚标题放在中间,使其变为白色并更改字体大小。

代码如下:

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    if (section == 3)
    {
        CGRect screenRect = [[UIScreen mainScreen] applicationFrame];

        UIView* headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 80, screenRect.size.width, 44.0)];

        UILabel *label=[[UILabel alloc]initWithFrame:CGRectMake(0, 80, tableView.frame.size.width, 80.0)];
        label.textAlignment = NSTextAlignmentCenter;
        label.textColor = [UIColor whiteColor];
        NSString* currentAppVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];

        label.text = [NSString stringWithFormat:@"Version: %@", currentAppVersion];
        label.font = [UIFont systemFontOfSize:14];
        [headerView addSubview:label];

        return label;
    }
    else
    {
        return nil;
    }
}

问题是,如果我在检查器中增加页脚边距的大小,它会为每个部分增加它,然后使部分之间的间隙变得更大。

我只想增加最后一节的页脚,以免标签被遮挡。

我也尝试过更改上面代码中的 UIView 和 UILabel 值,但没有成功。

对此的任何指导将不胜感激。

【问题讨论】:

    标签: ios static uilabel uitableview


    【解决方案1】:

    您可以使用委托方法- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section 。

    试试这样的:

    - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
        CGFloat footerHeight = 0;
        if (section == 3) {
            footerHeight = 100;
        }
        return footerHeight;
    }
    

    【讨论】:

    • 非常感谢 Mats - 这非常成功。我非常感谢您对此的回复,并对迟到的回复感到抱歉!再次感谢!
    【解决方案2】:

    SWIFT

    上面接受的答案满足了我的需求,只是想将其转换为 Swift 以供将来使用。

    override func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
    
        var footerHeight: CGFloat = 0
    
        if section == 3 {
           footerHeight = 100
        }
    
        return footerHeight
    }
    

    【讨论】:

      猜你喜欢
      • 2012-01-17
      • 2013-11-17
      • 2016-07-21
      • 1970-01-01
      • 2011-09-03
      • 2019-07-09
      • 2011-08-27
      • 1970-01-01
      • 2010-12-05
      相关资源
      最近更新 更多