gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 02:47:28 24 4
gpt4 key购买 nike

我实现了自定义页脚 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com