2013-01-16 115 views
1

我有一個屏幕顯示我目前處於回合制遊戲中的所有匹配。我正在使用3個部分的表視圖。將按鈕添加到UITableView頂部和底部

現在我想添加一個按鈕「開始新遊戲」到顯示遊戲上方的頂部。在展示遊戲下面,我需要幾個按鈕,比如'商店'等。我可以放置它們,但是它們不會滾動,因此我需要將它們放在tableview中,以便它們一起滾動。

這樣做的最好方法是什麼?

+2

頁眉和頁腳的景色。 – CodaFi

回答

1

我不知道究竟在何處,你希望你的按鈕,但UITableView中有
@property(nonatomic, retain) UIView *tableHeaderView
如果你希望它是在你的tableView的頂部,並用它滾動,只要你想要的視圖,並把它在那個屬性裏。

1

UITableView有一個tableHeaderView和一個tableFooterView屬性。您可以爲自定義視圖設置此值。

@property(nonatomic,retain) UIView *tableHeaderView;       // accessory view for above row content. default is nil. not to be confused with section header 
@property(nonatomic,retain) UIView *tableFooterView;       // accessory view below content. default is nil. not to be confused with section footer 

注:當您設置自定義視圖tableHeaderView/tableFooterViewn財產,其寬度將被廣泛的改變表視圖​​的

0

你的問題沒有那麼多清楚。在實現代碼如下我們,我們給了propertys property(nonatomic,retain)UIView * tableHeaderView;
@property(nonatomic,retain)UIView * tableFooterView;

,甚至你可以檢出該

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

你可以添加你的看法也在這裏。

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section 

此您可以將部分

3
UIView *headerContainer = [[UIView alloc]initWithFrame:CGRectMake(X, X, X, X)]; 
UIButton *btnHeader = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
[headerContainer addSubview:btnHeader]; 


UIView *footerContainer = [[UIView alloc]initWithFrame:CGRectMake(X, X, X, X)]; 
UIButton *btnFooter = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
[footerContainer addSubview:btnFooter]; 


tblView.tableHeaderView = headerContainer; 
tblView.tableFooterView = footerContainer; 

乾杯快樂編碼之間使用的高度!

1

添加的UIButton到導航控制器視圖這樣的代碼:

let createButton = UIButton.init(frame: CGRect.init(x: 0, y: self.view.frame.height-50, width: self.view.frame.width, height: 50)) 
createButton.backgroundColor = UIColor.orange 
createButton.setTitle("Create", for: UIControlState()) 
createButton.addTarget(self, action: #selector(didTapCreate(_:)), for: .touchUpInside) 
self.navigationController?.view.addSubview(createButton) 
相關問題