UIButton位于UITableView下方但位于TabBar上方

时间:2013-10-27 21:18:20

标签: ios uitableview

如何在UITableView下方但在TabBar上方放置一个按钮,以便UIButton静止(不用tableview滚动)?

以下是我想要帮助的图片:http://i.imgur.com/dY4CsDC.png

3 个答案:

答案 0 :(得分:1)

对UIViewController进行子类化并将UITableView和UIButton作为子视图放置。请参阅此问题的接受答案。

UITableView sticky footer / custom toolbar implementation

如果tableView中只有一个部分,您还可以将UIButton放在tableView页脚单元格中。使用...

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section

有关详细信息,请参阅文档

答案 1 :(得分:1)

简单!

在你使用你的tableview的UIViewController类中,你只需将子视图添加到相同的ViewControllers视图按钮并重新定位它们,以便它们中的每一个都拥有它自己的空间。

所以..

_tableView = [[UITableView alloc] init];

[_tableView setDataSource:self];

[_tableView setDelegate:self];

[_tableView setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];

// Use 64 to allow for the naviation bar on top and 160 to allow for tabbar and button
[_tableView setFrame:CGRectMake(0, 64, self.view.frame.size.width, self.view.frame.size.height-160)];

[[self view] addSubview:_tableView];



_aButtonUnderTableView = [UIButton new];

[_aButtonUnderTableView setAutoresizingMask:UIViewAutoresizingFlexibleBottomMargin];

// use 50 for the height
[_aButtonUnderTableView setFrame:CGRectMake(0, self.view.frame.size.height-100, self.view.frame.size.width, 50)];

[_aButtonUnderTableView setTitle:@"Custom Button Title" forState:UIControlStateNormal];

[_aButtonUnderTableView setBackgroundColor:[UIColor redColor]];

[_aButtonUnderTableView addTarget:self action:@selector(buttonTapped:) forControlEvents:UIControlEventTouchUpInside];

[[self view] addSubview:_aButtonUnderTableView];

现在 - tableview应该具有所有可用空间,但是从底部留下100像素偏移。并且它将自动调整,在双状态栏的情况下在底部留下100像素。

按钮将保持在底部(即使在双状态栏的情况下) - 始终具有可见的100像素高度。

答案 2 :(得分:0)

假设下载的数据将显示在上面的UITableView中,您应该创建UIView并使用UIButton(下载更多内容)并将此UIView设置为tableFooterView以上UITableView

tableView.tableFooterView = downloadView;