UITableView的自定义页脚视图不完全可见

时间:2014-07-24 10:30:46

标签: ios uitableview ios6

我实现了自定义页脚视图,但不幸的是我无法滚动它以使所有内容都可见。

有我的代码:

    UIView *footerView = [[UIView alloc] init];

    UIImageView *deliveryMainInfoImg = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 100, 100)];
    deliveryMainInfoImg.backgroundColor = [UIColor clearColor];
    deliveryMainInfoImg.image = [UIImage imageNamed:@"delivery-cost.png"];
    deliveryMainInfoImg.contentMode = UIViewContentModeScaleAspectFit;
    [footerView addSubview:deliveryMainInfoImg];

    CGFloat footerHeight = 0;

    NSString *txt = @"Some long text here ...";

    CGSize constraint = CGSizeMake(SCREEN_WIDTH - (3 * 10 + 100), SCREEN_HEIGHT);
    CGSize labelSize = [txt sizeWithFont:[UIFont fontWithName:@"HelveticaNeue-Light" size:SMALL_FONT_SIZE] constrainedToSize:constraint lineBreakMode:NSLineBreakByWordWrapping];
    footerHeight += labelSize.height;

    UILabel *deliveryMainInfoText =[[UILabel alloc] initWithFrame:CGRectMake(deliveryMainInfoImg.frame.origin.x + deliveryMainInfoImg.frame.size.width + 10, 10, SCREEN_WIDTH - (3 * 10 + 100), labelSize.height)];
    deliveryMainInfoText.backgroundColor = [UIColor clearColor];
    deliveryMainInfoText.textAlignment = NSTextAlignmentLeft;
    deliveryMainInfoText.font = [UIFont fontWithName:@"HelveticaNeue-Light" size:SMALL_FONT_SIZE];
    deliveryMainInfoText.textColor = [UIColor grayColor];
    deliveryMainInfoText.lineBreakMode = NSLineBreakByWordWrapping;
    deliveryMainInfoText.minimumScaleFactor = SMALL_FONT_SIZE;
    deliveryMainInfoText.numberOfLines = 0;
    deliveryMainInfoText.text = txt;
    [footerView addSubview:deliveryMainInfoText];

    UIImageView *deliveryExtraInfoImg = [[UIImageView alloc] initWithFrame:CGRectMake(10, deliveryMainInfoText.frame.origin.y + deliveryMainInfoText.frame.size.height + 10, 100, 100)];
    deliveryExtraInfoImg.backgroundColor = [UIColor clearColor];
    deliveryExtraInfoImg.image = [UIImage imageNamed:@"delivery-info.png"];
    deliveryExtraInfoImg.contentMode = UIViewContentModeScaleAspectFit;
    [footerView addSubview:deliveryExtraInfoImg];

    txt = @"Another long text ...";

    labelSize = [txt sizeWithFont:[UIFont fontWithName:@"HelveticaNeue-Light" size:SMALL_FONT_SIZE] constrainedToSize:constraint lineBreakMode:NSLineBreakByWordWrapping];
    footerHeight += labelSize.height;

    UILabel *deliveryExtraInfoText =[[UILabel alloc] initWithFrame:CGRectMake(deliveryExtraInfoImg.frame.origin.x + deliveryExtraInfoImg.frame.size.width + 10, deliveryMainInfoText.frame.origin.y + deliveryMainInfoText.frame.size.height + 10, SCREEN_WIDTH - (3 * 10 + 100), labelSize.height)];
    deliveryExtraInfoText.backgroundColor = [UIColor clearColor];
    deliveryExtraInfoText.textAlignment = NSTextAlignmentLeft;
    deliveryExtraInfoText.font = [UIFont fontWithName:@"HelveticaNeue-Light" size:SMALL_FONT_SIZE];
    deliveryExtraInfoText.textColor = [UIColor grayColor];
    deliveryExtraInfoText.lineBreakMode = NSLineBreakByWordWrapping;
    deliveryExtraInfoText.minimumScaleFactor = SMALL_FONT_SIZE;
    deliveryExtraInfoText.numberOfLines = 0;
    deliveryExtraInfoText.text = txt;
    [footerView addSubview:deliveryExtraInfoText];

    self.tableView.tableFooterView = footerView;

运行代码后,正如我所料,我需要有页脚,但部分内容不可见,当我试图滚动时,表只会反弹。

请帮助解决此问题。

感谢您的任何进展!

1 个答案:

答案 0 :(得分:1)

您需要替换

UIView *footerView = [[UIView alloc] init];

UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, width, height)];

并根据内容的大小将宽度和高度变量设置为正确的值。