[英]UIButton below a UITableView but above a TabBar
如何在UITableView下方但TabBar上方放置按鈕,以使UIButton固定(不使用tableview滾動)?
這是我想幫凶的照片: http : //i.imgur.com/dY4CsDC.png
子類化UIViewController並將UITableView和UIButton放置為子視圖。 請參閱有關此問題的公認答案。
如果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.