Reputation: 29519
In my storyboard I have UITableViewController which has custom class. How can I add UIView objects on top and bottom parts of the table view?
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?
Upvotes: 1
Views: 3563
Reputation: 111
Yes it's possible in 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()
Upvotes: 1
Reputation: 41236
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. This would allow you to layout the main view contents around the table and still keep a separate UITableViewController maintaining the table itself. Set up the right auto layout constraints (really simple, just anchor the container view to the header and footer views)
Upvotes: 3
Reputation: 5902
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];
Upvotes: -2