ios - UITableView 的自定义页脚 View 不完全可见

标签 ios uitableview ios6

我实现了自定义页脚 View ,但不幸的是我无法滚动它以使其全部可见。

这是我的代码:

    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;

运行代码后,正如我预期的那样,有我需要的页脚,但其中一部分不可见,当我尝试滚动它时,表格只会弹起。

请帮忙解决这个问题。

感谢您的帮助!

最佳答案

你需要更换

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

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

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

关于ios - UITableView 的自定义页脚 View 不完全可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24931284/

相关文章:

objective-c - iOS6 和 UITableView 中的离屏 UITextView

uitableview - 无法快速访问tableviewcell的属性

ios - iPhone 5 模拟器返回错误的屏幕尺寸

ios - 如何生成所有可能的组合?

ios - 隐藏或更改手势栏颜色的代码或设置(也称为应用程序切换器)iOS 10+

ios - 如何从父类调用一个方法到它的子类?

iphone - ios5中如何使用identifierForVendor?

iphone - 没有设备的iOS越狱开发

ios - 你能拥有多个 UnityAppController 的子类吗?

java - 100% CPU 在 javapns 中使用