繁体   English   中英

如何根据方向/ UITableView宽度更正tableview节标题框架

[英]How to correct the tableview section header frame according to the orientation / UITableView width

我有一个分组样式的UITableView-我有一个自定义标题视图:

+ (UIView *) viewForHeaderWithText: (NSString*) title
{
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
    {
        UIView *viewHeader = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 20)];
        UILabel *label = [[UILabel alloc] init];
        label.backgroundColor = [UIColor clearColor];
        label.frame = CGRectMake(10.0f, 0.0f, 300.0f, 20.0f);
        label.font = [UIFont systemFontOfSize:12.0f];
        label.textColor = [UIColor blackColor];
        label.textAlignment = NSTextAlignmentLeft;
        label.text = title;
        if (!IS_OS_7_OR_LATER) {
            label.textColor = [UIColor lightGrayColor];
        }
        [viewHeader addSubview:label];
        return viewHeader;
    }
}

因此,节标题宽度框架是固定的。

但是对于不同的方向和呈现UITableViewController的方式,更改了单元格宽度(iOS6)-如您在屏幕截图中所见。 但是我需要使节标题和单元格的偏移量相等。

我现在有:

在此处输入图片说明在此处输入图片说明

我需要的:

在此处输入图片说明

我试图更改像元宽度-但无法解决此问题。有什么帮助吗?

您需要在uitableView委托方法下面实现此功能:-

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM