我正在使用目标 C 中的 X-Code 开发 iPhone 应用程序。我想在表格底部添加一个蓝色页脚(与页眉相同)。
任何人都可以帮助我建议如何实现这一点。另外如何在此页脚中添加按钮。
提前致谢。
我正在使用目标 C 中的 X-Code 开发 iPhone 应用程序。我想在表格底部添加一个蓝色页脚(与页眉相同)。
任何人都可以帮助我建议如何实现这一点。另外如何在此页脚中添加按钮。
提前致谢。
希望对你有帮助
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
UIView *viewFotter = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 44)];
[viewFotter setBackgroundColor:[UIColor blueColor]];
return viewFotter;
}
但问题是,你不能调整按钮的大小。因为它对我不起作用。
将此代码粘贴到您的.m
文件中,您也可以在页脚视图中添加图像
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
return 44;
}
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
UIView *viewFotter = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 44)];
[viewFotter setBackgroundColor:[UIColor blueColor]];
UIButton *GoBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[GoBtn setTitle:@"GO" forState:UIControlStateNormal];
GoBtn.frame = CGRectMake(85, 7, 150, 39 );
[GoBtn addTarget:self action:@selector(GOButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
[viewFotter addSubview:GoBtn];
return viewFotter;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
return 40;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 40)];
footerView.backgroundColor =[UIColor blueColor];
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
[btn setTitle:@"BUTTON" forState:UIControlStateNormal];
btn.frame = CGRectMake(100, 5, 100, 30 );
[btn addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
[footerView addSubview:btn];
return footerView;
}
-(void) btnClicked:(id) sender{
//ur code
}
您可以使用所需的组件( 、 等)创建自定义视图,UIButton
并UIImageView
在
-(UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
或者您可以将相同的视图分配给 tableFooterView
tableView.tableFooterView = yourBlueView;
您可以通过将按钮拖动UIButton
到 xib 的页脚来添加按钮UITableView
。但是您不能调整按钮的大小,因为它会自动分配给表格视图的宽度。但我不明白你在说什么关于页脚颜色。你能详细说明一下吗?