Reputation: 4755
I have added a UIImageView
on top of my tableView
in storyboard & it works perfectly fine, except that when you scroll down, the imageView
doesn't stick to the navigationBar
and instead only sticks on to the tableView
(revealing the view's background above it).
How would I get it to stick to both the tableView
and the navigationBar
, and just have the imageView
stretch/zoom as the user pulls the tableView
down?
This is how it's set up in storyboard:
And this is how I assign an image to it in my ViewDidLoad:
childHeaderView.image = [UIImage imageNamed:headerImage];
Any help would be greatly appreciated. I've tried setting constraints on it using autoLayout but it doesn't seem to let me (they're grayed out, even though I've enabled it for that ViewController
).
Upvotes: 0
Views: 1116
Reputation: 11006
The problem is that what you did in storyboard is adding the UIImageView
as a header to your UITableView
.
The proper way to do this is to add the UIImageView
at the same level as the UITableView
, which mean embed these two views inside a UIView
.
Having a UIView
as a root view for a view controller is unfortunately impossible for a UITableViewController
, and I fear that this is your case. So you may want to replace your UITableViewController
subclass by a UIViewController
subclass.
EDIT: You'll want to set a fixed height constraint on your UIImageView
, and add a vertical space constraint with a 0pt value between your UIImageView
and UITableView
.
Most of these can be achieved by moving view in IB.
Upvotes: 1