2013-01-16 116 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) 
相关问题