繁体   English   中英

UITableView下方但TabBar上方的UIButton

[英]UIButton below a UITableView but above a TabBar

如何在UITableView下方但TabBar上方放置按钮,以使UIButton固定(不使用tableview滚动)?

这是我想帮凶的照片: http : //i.imgur.com/dY4CsDC.png

子类化UIViewController并将UITableView和UIButton放置为子视图。 请参阅有关此问题的公认答案。

UITableView粘性页脚/自定义工具栏实现

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

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

请参阅文档以获取更多详细信息

简单!

在使用表视图的UIViewController类中,只需将与子视图相同的ViewControllers视图按钮添加到相同的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 pix。

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

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

tableView.tableFooterView = downloadView;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM