[英]Add top/bottom views to UITableViewController?
In my storyboard I have UITableViewController which has custom class.在我的故事板中,我有 UITableViewController,它具有自定义类。 How can I add UIView objects on top and bottom parts of the table view?
如何在表格视图的顶部和底部添加 UIView 对象?
Do I have to create UITableView and two desired views inside of UIView and then manually init my controller, set tableView or there is a better way?我是否必须在 UIView 中创建 UITableView 和两个所需的视图,然后手动初始化我的控制器,设置 tableView 还是有更好的方法?
If you're wanting to use UITableViewController for it's abilities to manage cells and static layouts, the best possibility would be to use a container view in your storyboard.如果您想使用 UITableViewController 来管理单元格和静态布局,最好的方法是在故事板中使用容器视图。 This would allow you to layout the main view contents around the table and still keep a separate UITableViewController maintaining the table itself.
这将允许您围绕表格布局主视图内容,并且仍然保留一个单独的 UITableViewController 维护表格本身。 Set up the right auto layout constraints (really simple, just anchor the container view to the header and footer views)
设置正确的自动布局约束(非常简单,只需将容器视图锚定到页眉和页脚视图)
Yes it's possible in UITableViewConroller:是的,在 UITableViewConroller 中是可能的:
let bottomView = UIView()
bottomView.backgroundColor = .red // or your color
bottomView.frame = CGRect(x: 0, y: UIScreen.main.bounds.size.height - 78, width: tableView.frame.size.width, height: 78) // 78 or your size of view
navigationController?.view.addSubview(bottomView)
tableView.tableFooterView = UIView()
Something like this should work for you:这样的事情应该适合你:
// Your frame/view will vary
UIView *subview = [[UIView alloc]initWithFrame:CGRectMake(0, 64, 320, 44)];
subview.backgroundColor = [UIColor redColor];
[self.navigationController.view addSubview:subview];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.