UICollectionView layout with custom layout - ios

Is it possible to create a collection view with an item on the left and two items stacked to the right of it?
Whenever I specify the correct sizes to do this in the sizeForItemAtIndexPath delegate I can only get one item on the right side and the other is displayed in the next row underneath. I know I can do this with custom cells that contain more than one view (top and bottom) but I would like to know if its possible without that. It would be a lot less complex if I could do it without the custom double view cell. Im using a 'flow' layout with 'vertical' scroll direction (as per IB).
First image is what I hope to achieve and the second is what I am able to achieve currently.

You need to implement custom UICollectionViewFlowLayout subclass for this - Creating Custom Layouts

Related

How do I implement the below view in iOS (Objective-C or Swift)?

Basically I'm trying to implement the feature which is attached as an image. I'm trying to create generic component. Where view can have list of items and minimum that could be shown will be two and there should be a button with 3 more options and click on should expand the view and auto adjust with the container using auto layout. Can any one help me giving brief idea how do I implement this? would be really help full.
Image and Component that I'm trying to implement is as below:
You will use UITableView with 2 UICustomCell one for default view like your image and another for expand view, use NSMutableArray to save flag value that decide to use the first cell or second cell, and in UIButton action reset this array and reload your UITableView.
I hope I help you.
1) If I right understand, the flexible solution it's creating UITableViewCell and UICollectionView as one of subviews (another - UIImageView). UICollectionView has two kinds of cells:
Cell with label - item.
Show more button.
Each time when you press Show more button just can reload UICollectionView without restrictions or insert new items.
But in this case you should manually calculate tableview's height. Implement sizeThatFits in UITableViewCell.
2) Also can add UIStackView and use it for your goal but UIStackView has bad performance.
Hope it helps you!

Implementing scrollable horizontal menu

I am new to iOS and trying to implement something exactly like the scrollable bar with the various sports show here.
I want the user to be able to scroll horizontally through the various options and be able to select one. It can be very simple like the one linked, as long as it is clear what is selected.
I'm not sure where exactly to start. Should I be using a CollectionView?
You are right - UICollectionView is the best option for you. Do set the collectionView's layout to UICollectionViewFlowLayout with horizontal direction.
Setup the UIViewController to be the collectionView's data source and delegate. The selection with tapping will be available immediately provided by default UICollectionView behaviour. The collectionView's delegate will allow you to intercept the event when collection is scrolled to new item so you would be able to determine the new selected item.

UICollectionView two cells in a single row

I am trying to layout a vertical scrolling collection view cells to layout like this
When I tried to size the cells like that it made the bottom right one go onto the next line instead of group them together.
Take a look at the UICollectionViewLayout class. There you should find methods you need to achieve your desired look.
https://developer.apple.com/library/prerelease/tvos/documentation/UIKit/Reference/UICollectionViewLayout_class/index.html

Is it possible to merge the cells in a UITableView so that i can add some image at the right side?

As seen in the image of my design that i have attached, i want to merge(don't know wether thats the correct word) the first three cells so that i can display an image at the right side in the table itself. Is it possible?
No it's not possible. Instead, you can create first three as one cell(type1), other cells are other type(type2).
Update: see this tutorial for how to create custom cell.
You can create a UIView with fixed dimensions(say, 200x200) having 3 textfields (number, name & uom) to left and add UIImageView to right. Create IBOutlet of this view and name it. Add this view to the header of your UITableview.
self._table.tableHeaderView = yourview;
You should use a UICollectionView instead and apply a custom layout to achieve this.
Collection views provide the same general function as table views
except that a collection view is able to support more than just
single-column layouts. Collection views support customizable layouts
that can be used to implement multi-column grids, tiled layouts,
circular layouts, and many more. You can even change the layout of a
collection view dynamically if you want.
There are many tutorials on the Internet:
http://skeuo.com/uicollectionview-custom-layout-tutorial
http://www.raywenderlich.com/22324/beginning-uicollectionview-in-ios-6-part-12
Another option is to use UITableView and a custom UITableViewCell.
Example:
http://www.idev101.com/code/User_Interface/UITableView/customizing.html
add it in the first cell.The size of you imageview shoud be greater than the cell height.Make sure cell.cliptobounds is set false.Make sure you set the zpositon of imageview to 1 by imageView.layer.zPosiziton = 1.
Actually, you can add your imageView as subview of tableView, so your didSelectRowAtIndexPath: will working as usual

What's the best way to build a very flexible/dynamic "header" in UICollectionView

I need to build a UICollectionView with a UICollectionViewFlowLayout and a very dynamic "header" (for clarity, I'll call it "view A" to avoid mixing it with a true collection view header) but I'm not sure about what can be the best way to do that: collectionViewCell, header or supplementary view?
What I mean by flexible, the bullet point being ordered by decreasing importance:
View A will contain buttons and subviews that need to detect gestures so I must be able to detect actions on subviews of view A.
I need to be able to reload data on the collection view without reloading view A.
I need to be able to update the layout of subviews of view A whenever I want (on viewDidScroll of the collection view delegate for example, update according to contentOffset changes).
If possible, I'd like to be able to change the frame of view A dynamically (I mean without having to invalidate the layout). I would like view A to be sticky at the top and shrink while scrolling until it disappear. Have a look at recently launched "Secret" app to see what I mean (done on UITableView for them). Though I could just scroll without changing the frame and cheat by changing the layout of subviews (see point 3) in order to give the sensation of a sticky header.
What do you think is the best component to do that? Can I use a UICollectionViewCell, a header or a supplementary view? If so which one? If not, do you think of an alternative way I could use to have the same behavior (transparent header and view A behind the collection view? adding view A somewhere else, where, in the view hierarchy?).
Thanks for your help!
Take a look at the UICollectionReusableView class.
You can register your nib on the CollectionView as "SupplementaryView" (registerNib:forSupplementaryViewOfKind:withReuseIdentifier:, use the UICollectionElementKindSectionHeader kind of view)
then you have to implement the collectionView:viewForSupplementaryElementOfKind:atIndexPath: method in your delegate and make sure to return something for the UICollectionElementKindSectionHeader kind.
and finally you have to implement the collectionView:layout:referenceSizeForHeaderInSection: method of your UICollectionViewDelegateFlowLayout to set the size of your header.
Let me know if it help.

Resources