I have a screen in my storyboard where I would like to embed a container view into a portion of the screen. I can't figure out if I should add a new containerview or view from the object library and then drag in a collection view controller or collection view (or tackle it a different way?). I've tried all combinations but just end up with the embedded view being shown black even if I drag collection view cells and set a background colour to test it. Once I can get this working I plan to populate the cells from an external database.
Any suggestions please? I'm doing this using storyboard as far as possible.
Thank you.
After you drag a container view into your view, you automatically get an embedded view controller, whose size is matched to the container view's size. You should delete that controller, and drag in a UICollectionViewController. Control drag from the container view to this controller and choose embed when you let go -- this will resize the collection view controller. You can give the collection view a background color, so you will see where it is, but giving the cells a background color won't show up until you implement the methods in the controller to populate those cells.
Related
I have a table view controller with static cells. I’m running on iPhone X and when scrolling, the cells appear to be behind the navigation bar and unsafe area. What is preferred would be a solid orange color in the unsafe area instead of the image presented below. Is this possible? I can’t move to a table view inside of a view controller, which I would then constrain to the safe area, because my cells are static.
You need to use a Container View, so add a View Controller in your storyboard and put a Container View in it-by adding the container view it will automatically create a segue and a view controller delete both.
Now from your Container View create a segue to the Table View Controller and choose Embed.
Last step is to set the constraints for your Container View, the most important for your issue is the top one, set it 0 to the safe area.
I would like to create such a layout where on scroll the imageview hides and collection view takes whole screen. I tried this but it doesnt seem to work. I am getting the image view correctly but the collection view has gone dark completely on run. I have a content view(UIView) and scroll View underneath. Thank you
EDIT 1 :- The Cells are not getting displayed. But the collection view is displayed in the layout. How to solve this?
EDIT 2 :- Instead of using the collection view directly I used a container view and embedded my collection view in it and it Worked! However I am still trying to figure out how do i scroll the container view to top when i scroll, i.e. push the image view on the back of container view while it takes the full height of the screen.
Okay So I figured it out.
Wreck all of the above. (Though the container view solution is pretty good)
Build a collection View controller from scratch having 2 headers, one is the standard and the other one for the image view.
Make your view controller a delegate of the collection view flow layout delegate and implement function for referenceSizeForHeaderInSection
Do not forget to register for the xib yo have created for the image view header by using registerNib forSupplementaryViewOfKind function of collection view object.
I was trying to build home base application which mean there are many icon at root view and it will navigate to appropriate view. So, I will use collection view for it. But, the problem is when I add button to the collection view, the button didn't scroll with collection view, when I scroll collection view up. Here is my simulator build:
As you can see,the button "Click here to login" didn't scroll up with collection view. So, is there any way that I can add button to center of collection view which will scroll with collection view?
Here is my storyboard :
What am I doing wrong?
When you take a closer look at your view hierarchy in Interface Builder you'll notice that the button you added isn't actually a subview of your collection view. I added a red line to indicate which objects belong to the collection view.
Your login button is on the same level as your collection view in the view hierarchy. Both are subviews of your view controller's root view. So no wonder the button doesn't scroll with the collection view.
However, you cannot simply add an arbitrary view (or button) to the collection view itself in Interface Builder. You'll need to add a Collection Reusable View first as your collection view header and then add your button to it.
Your storyboard scene in Interface Builder will then look like this:
Please note that you'll also need to add some code to your collection view data source (which will probably be the same as your collection view controller) in order to make this work.
I have a UIViewController in storyboard that will be a sliding up menu. I want to place it in a UITableView. If I place it as subview of UITableView and prevent it from scrolling, it gets the look I want, with one problem, the section headers of tableview scroll above subview.
Now, in order to prevent this behavior, I could reduce tableview frame, but it doesn't work because my subview is inside that same frame, right?
So , if that is true, what is the best way to achieve this? Place both screens inside a third UIViewController?
Don't try to put other views inside a table view. Bad news.
If your table view is managed by a UITableViewController then that's really all you can have in the table view (unless your views are inside cells, or in headers or footers.)
If you ARE using table view controllers to manage your table view(s), I suggest you create a container view on the view controller that needs to contain the table view, then control-drag an embed segue to the table view controller. That way the table view controller becomes a child view controller of the main VC, and you can put other view elements on the screen to your heart's content.
I'm trying to add my custom ContainerView to an usual ViewController using StoryBoard (iOS7).
I only have a TableView Controller on this view. If I move the ContainerView inside the TableView it is displayed (but moved with the table items), but if I place it directly on view it is not displayed any more! Any ideas?
There appears to be a bug in Xcode/iOS where if the container view is the first child of self.view in storyboard, it doesn't show. For example when I have:
my container doesn't show.
But if I move the label above the container view in the outline:
Then my container view and the label will show.
UPDATE: Upon further investigation it appears the container view does still show if it is the first child, just much lower than you would expect it to appear. Placing another element above the container view allows the container to appear in the position you would expect (the position shown in storyboard).