如何获得tableView和tabBar之间的大小?
我有动态UITableView
。 当行不足以填充屏幕时,我将以编程方式绘制UIView
并将其设置为self.tableView.tableFooterView
。 空行有图像(红线)。 我需要知道尺寸x(见图),知道需要绘制多少行。 我怎么才能得到它?
您可以获取contentSize并从表视图的帧大小中获得差异。 例如:
let space = tableView.frame.height - tableView.contentSize.height
如果内容多于tableView高度(如果它滚动),则此值将为负值,在这种情况下,只需将其替换为0。
此外,您还必须添加单元格并调用reloadData()
。
其他选项是将行数乘以tableView.rowHeight
(如果它已修复),或者为每一行调用tableView:heightForRowAtIndexPath:
并将它们全部加在一起。
尝试
- (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; }