如何获得tableView和tabBar之间的大小?

时间:2015-04-27 15:08:53

标签: ios uitableview swift

我有动态UITableView。当行不足以填充屏幕时,我将以编程方式绘制UIView并将其设置为self.tableView.tableFooterView。空行有图像(红线)。 我需要知道尺寸x(见图),知道需要绘制多少行。我怎么能得到它?

enter image description here

2 个答案:

答案 0 :(得分:1)

您可以获取contentSize并与表视图的帧大小区别开来。例如:

let space = tableView.frame.height - tableView.contentSize.height

如果内容多于tableView高度(如果它滚动),则此值将为负值,在这种情况下,只需将其替换为0.

此外,您还必须添加单元格并调用reloadData()

其他选项是将行数乘以tableView.rowHeight(如果已修复),或者为每行调用tableView:heightForRowAtIndexPath:并将它们全部加在一起。

答案 1 :(得分:0)

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];

    CGSize statusBarSize = [UIApplication sharedApplication].statusBarFrame.size;
    CGSize navigationBarSize = self.navigationController.navigationBar.frame.size;
    CGSize tableViewContentSize = self.tableView.contentSize;
    CGSize tabBarSize = self.tabBarController.tabBar.frame.size;

    UIView *tableFooterView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, tableViewContentSize.width, self.tableView.frame.size.height - statusBarSize.height - navigationBarSize.height - tableViewContentSize.height - tabBarSize.height)];
    tableFooterView.backgroundColor = [UIColor redColor];
    self.tableView.tableFooterView = tableFooterView;
}