UICollectionView header view like table view header - ios

Is it possible to create UICollectionView header view like UITableView headerView? I mean header view for whole collection view, not the repeated one for each section.
If that's impossible, then how could I add outlets to section view subviews from Storyboard?

Eventually I put UICollectionView in UITableViewCell and added some code to calculate cell height.

Related

Collectionview inside tableview cell with dynamic height cells and dynamic content swift 4

I am working with collectionview inside tableviewcell in Swift 4. I get the content from server which is all dynamic. I have to show different types of collectionview behaviours.
For example, in the first tableview row should be collectionviewcell with screenwidth and scrollable. In the second row, collectionview with 3 sections and each section has different content different number of items.
Here I got stuck I am unable to show 3 sections one below other it is showing besides horizontally. I have calculated collectionview flow layout size.
Also in last row I have collectonviewcell with scrollable content,here when i scoll the content is repeating from bottom row or top row. I want the smoth scrolling and to stop repeating the content.
I am new to Swift. Can anybody help me out of this . Thanks in advance.
The smooth way is to create tableview with its cell xib and inside its cell add collection view and create another xib for collection view cell. This method is helpful when accessing collection view for different tableview cell. Rather using without loading Xib's may mixup your code.
You have to set tableview cell height as UITableViewAutomaticDimension. This will handle your cell height as per your dynamic content.
For each tableview cell you have to set collection view's property by using cell's index path as per your requirement.

Uitableview with UICollectionviewcell and UITableviewcell

i need to create below design
I am following this code to draw simple collection view with horizontal scroll inside a UITableView
Current sample code work like this
UITableView-> UICollectionViewCell as cell with horizontal scroll
What i want
i want : First row with UICollectionview with horizontal scroll and
Then rest row with Normal UITableviewCell to show data
How can i do it .
add a UITableView to your view controller and implement it's delegate and datasource methods .(You can use UITableViewController instead of UIViewController).
for the fist cell of the first section in your tableview, you should use a custom tableview cell.
Inside this custom tableview cell, you have to add your collection view with horizontal scroll, and implement its delegate and data source methods inside your custom tableview cell class.
these are the steps you have to do.
refer this implement uicollectionview inside uitableview question for more.
Hope this will help to you.
You should design a UITableViewCell which has a UICollectionView inside, and set this cell for the cell in section A and for Section B, you should design a new UITableview cell.
When tableview's cellForRowAtIndexPath call you can check for First section and when first section load you can create new UICollection view object load in first cell. Than next section will load you can work as normal tableview work.
Not- you need to implement UICollectionview delegate and datasource methods also.

How to put UIView inside of UICollectionView?

I want to put my UIView inside of UICollectionView(on top) that on scroll it scrolls with UICollectionView content. It's possible to put it on header part in UITableView, I did it, but in UICollectionView I cannot achieve the same effect. How can I do it?
I have created GitHub repo with sample. If anyone could help me with it.
In UITableView I add UIView inside of UITableView and it stays there, but in UICollectionView it stays behind of UICollectionView. I want that it(UICollectionView sections) will stay under the UIView and on scroll all(UIView & UICollectionView sections) will scroll together.
There is no such thing as collection view footer or header, because the layout can be very different depending on your needs, but, you have a couple of function that can help you for example:
registerClass(_:forSupplementaryViewOfKind:withReuseIdentifier:)
or
registerNib(_:forSupplementaryViewOfKind:withReuseIdentifier:)
depending if you are using a nib file or not.
I'm not sure but you will also need to provide the height of the view in the layout delegate
UICollectionViewDelegateFlowLayout
you can do this by dragging your UIView on to your cellidentifier of UICOllectionView
Like i did see in snapshot:
here View is my UIView which i added to UICollectionView and it scroll with the CollectionView

How to apply parallax effect to UITableView header that contains horizontal UICollectionView?

I created screen that contains UITableView. The tableView header contains horizontal UICollectionView and that collectionView contains cells with imageView and some other view.
The question is how to apply parallax effect to all view in the tableView header?
Implement the UIScrollViewDelegate method scrollViewDidScroll. There you can examine the contentOffset of the table view and modify the collection view height (via the constant of a NSLayoutConstraint) and its contentOffset.

UITableView inside UICollectionView handling touches.

Collection view consists of a single row, of horizontally aligned cells, which size is the same size as the collection view's bounds, single cell fills entire screen.
The problem is that the collection view seems to be intercepting all of the pans. How can I forward them to the table so I can also scroll the table vertically.
I want vertical pan to be delivered to the table inside the cell, so it can scroll up and down. I want horizontal pan to be delivered to the collection view, so it can scroll horizontally.
Any ideas? Thanks.
For UITableView inside CollectionView using storyBoard, please follow these steps:
-Drag CollectionView to UIViewController, drag datasource to UIViewController(don't drag delegate). Add datasource methods inside ViewController.m
-Create Cell:CollectionViewCell class. choose class for Cell in storyBoard to Cell class,specify reuse ID.
-Drag tableView inside collectionCell square. delegate, datasource drag to CollecionCell Square too. Add tableView datasource, delegate inside Cell.m
-Create CellDelegate when implement tableViewDidSelect inside it. Transfer this delegate to UIViewController to perform other action
Sample code: https://github.com/lequysang/github_zip/blob/master/TableViewInCollection.zip
Swift2 update - We don't need to do all the above steps. Just making the controller the delegate and datasource of both the tableview and collection view works just fine.
I've been able to make this work without using storyboards--although, I use XIBs for my views but only to add the Autolayout rules. All customisation (colors, fonts, labels, etc.) are set in code. In any case, this should also work for cells that are being built programatically.
How to do it:
The most important thing to remember is to add your custom view to the contentView property of the cell and not inside the cell itself. If you are using XIBs for the custom UICollectionViewCell, leave it blank. Instantiate your custom view (where the UITableView is), then add it as a subview of the UICollectionViewCell's contentView. If you add the table vie directly inside the collection view cell, the table view will not vertically scroll.
Implement shouldSelectItemAtIndexPath and shouldHighlightItemAtIndexPath of the UICollectionViewDelegate and make both return false, so that tapping on the collection view cell does not intercept with taps intended for the table view inside.
Done with Xcode 7.3 for iOS 9+.

Resources