iOS: Stretching ImageView Above My TableView? - ios

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).

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.

Related

Why I cannot apply constraints to the photo in the UITableView header?

In my storyboard I have a UITableView and above the dynamic cells I added a UIView to keep there a photo and some labels.
Currently, I want to apply constraints to the photo so that it reaches the top, left and right side of the screen and keeps the aspect ratio. However, the storyboard looks like this:
The constraints for photo are:
However, as you see, the constraints are marked in red and when I run the app the photo is not stretched properly.
What is causing this issue?
I would probably do this programmatically. It is pretty simple to create a custom view and set it as your header view. You can either create a UIView with a UIImageView inside of viewForHeader or by assigning it to the entire table with tableView.tableHeaderView = headerView.

How to add a custom view to top of tableView in UIViewController and be able to scroll together

I'm trying to put a big UIImageView on top of a UITableView inside my UIViewController. I read that I should not put a UITableView inside a UIScrollView and so I'm trying to find out how to best approach this.
Right now, in my UIViewController what I have is a huge UIImageView (covering half of screen) and below that I have my UITableView.
The problem is that the scroll only works for the UITableViewCell, but I cannot scroll up so that the image goes to the top and invisible...
Thanks for the help!
Make the tableview the height of the view controller's view then in viewDidLoad say something like:
self.imageView.removeFromSuperView()
self.tableView.tableHeaderView = self.imageView
If you're using auto layout you should move the second line to viewsDidLayoutSubviews

tableviewcell does not stretch at landscape ie., orientation change

I need a fixed header that does not go from view. I intend to keep summary of tableview below. So I started off with a UIViewController and trying to put UIView and UITableView under that.
In UIView I added a UIButton, UILabel but I'm running into layout constraints.
In UITableView, when I change orientation cell is not filling up the view. why is that? Am a newbie to ios programming. Appreciate any pointers.
Pl see the images below.
Looks like You didn't pinned all your tableview edges with superview thats why this happened..
select tableview and Pinned all edges of tableview with superview thats all..see below image

UIView at bottom UIScrollView does not appear

I'm trying to get an UIScrollView working with my Storyboard. It works but the UIView at the bottom that I use with a gesture tap for getting back is not showing. How can this be?
So everything works expect that. This are the things that I did:
Set freeform in Storyboard
Disable auto layout for the Storyboard nib
Changed the freeform dimensions to X:320 Y:800
Dragged some labels and stuff in the Scrollview
Created an outlet for the ScrollView
Enabled scroll programmatically
Enabled Contentsize CGMakeSize() programmatically;
So I normally did everything, why isn't my UIView showing up at Y:750. The only thing I do with the UIView is setting the Background/CornerRadius.
It would be if your UIView is no included in the calculation for the content size. Other than that I cannot see anything obvious.

TableView doesn't not scrolling and cells is not enabled

I've created UIImageView with tableView and put this view on another view. But my table isn't enabled. I can't press on the cell or scroll my table.
Try creating a UIView with your UIImageView and UITableView as subviews.
I don't think it's a good idea to have your table as a subview of an imageview.
I suppose you did this to have a background image for the table, but a transparent table with an image view behind can easily achieve this effect.
Do you have a UITableView as a subview of a UIImageView?
If that is the case then the problem is probably that userInteraction is disabled on your UIImageView (it is set to NO as default for UIImageViews).
You can try to set it to YES and see if you can interact with your UITableView. However I would not recommend this view structure as I don't believe it is intended to put UITableViews as subviews to UIImageViews

Resources