在我的回合制游戏中,我有一个显示我当前所有比赛的屏幕。我正在使用包含3个部分的表格视图。
现在我想在显示游戏的上方添加一个“开始新游戏”按钮。在显示游戏下面我想要几个按钮,比如“商店”等。我可以放置它们但是它们不会滚动所以我需要将它们放在tableview中以便它们滚动。
最好的方法是什么?
答案 0 :(得分: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 :(得分:1)
我不确定你想要按钮的确切位置,但是UITableView有一个
@property(nonatomic, retain) UIView *tableHeaderView
如果您希望它位于tableView的顶部并使用它滚动,只需创建您想要的视图并将其放在该属性中。
答案 2 :(得分: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属性时,其宽度将更改为与表视图的宽度
答案 3 :(得分:1)
将UI按钮添加到导航控制器视图,如下代码:
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)
答案 4 :(得分:0)
你的问题不是那么清楚......在tableview中我们给了一个属性
属性(非原子,保留)UIView * tableHeaderView;
@property(非原子,保留)UIView * tableFooterView;
甚至你可以查看这个
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
你也可以在这里添加你的观点。
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
这可以用于各部分之间的高度