Reputation: 37581
I have a green navigation bar and a green table view header that together look like this:
But when the user scrolls the table view down it appears like this:
I'm attempting to set the color of the grey portion that is revealed when the user drags down to also be green, but can't work out how to do so.
If I set the tableview's background color to green this does not affect it, setting that to green sets the view behind the grey strip but does not affect that strip itself:
Here is the grey strip in the view hierarcy:
Is there some way I can set it to green, so when the user drags down they don't see they gray beneath?
The table view in the storyboard is like this:
Upvotes: 1
Views: 319
Reputation: 263
Dobiho's answer in Swift:
var frame = tableView.bounds
frame.origin.y = -frame.size.height
let bgView = UIView(frame: frame)
bgView.backgroundColor = UIColor.green
bgView.autoresizingMask = .flexibleWidth
tableView.addSubview(bgView)
Upvotes: 0
Reputation: 1035
I had a same problem, I solved it with this code.
CGRect frame = self.ContactTable.bounds;
frame.origin.y = -frame.size.height;
UIView* bgView = [[UIView alloc] initWithFrame:frame];
bgView.backgroundColor = [UIColor systemBackgroundColor];
bgView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
// Adding the view
[self.tableView insertSubview:bgView atIndex:0];
Upvotes: 1
Reputation: 17724
Use the backgroundView
property of UITableView
:
let backgroundView = UIView()
backgroundView.backgroundColor = UIColor.green
tableView.backgroundView = backgroundView
It will automatically resize to the size of the table view.
Upvotes: 0