UICollectionView for Grid Layout with Xamarin.iOS (MonoTouch)? - iphone

I was wondering if there is a UICollectionView implementation around for displaying views (images) in a grid as shown below.
I started to build it with UITableView, but it is getting really complicated if an item doesn't fit in the same row with its predecessor/successor.

I came across this the other day, which is similar to what you want to do and may work out:
http://pierceboggan.com/post/56951869926/pinterest-style-uicollectionviews-in-xamarin-ios
It is a modification of a UICollectionView made to work like the waterfall layout that Pinterest uses.

The default UICollectionViewFlowLayout, in horizontal mode, can do a lot of what you need, but it can't do the yellow cells, spanning multiple rows.
You could subclass the flow layout, and modify the layout attributes for each cell to have the correct position and size.

Related

Swift IOS - a complex table view cells' arrangement

All. I am new to Swift. I am trying to create something similar to the image attached below. My question is regarding the table view.
I create a prototype cell for each recipe, in which contains an image View and a textfield. However, how should I arrange those cells like those in the picture attached?
It seems that each cell has a different height. I thought about including multiple recipes in one prototype cell, yet it may not be the right solution.
In the real world, how do people handle such arrangements? Maybe people use something other than prototype cell?
Your help is greatly appreciated. Thanks in advance.
You can achieve this thing by using collectionview. If you know width and hight in advance then you can simply create collectionview with constant width and height of cell. if you don't know the dimensions in advance you need to do some extra task in collectionview which is selfsizingcell.
This is called 'waterfall collection view', you can find similar thing in Pinterest app. Size of each cell is dynamically calculated based on the width&height of picture itself.
Personally I've used this open-source github project, in order to implement same thing in my app.

NSCollectionView Flow Layout and random row justify

I'm showing some photos with a NSCollectionView in FlowLayout. This works fine. Then I wanted to use dynamic width for each item for better distribution of the images when some are landscape and some are portrait.
So I implemented the collectionView(_:layout:sizeForItemAt:) to return sizes.
And now I have a strange behaviour on rows with less items then is space available. Sometimes the lines are filled from left to right with great spacing between the images (justify) and sometimes they are just half filled rows with the defined minimum item spacing (left aligned).
I like the left aligned version, but reading the docs the justified version should be the correct one. But why it is randomly sometimes this and sometimes the other way?
How can I do something against it?
Do I have to implement my own custom flow layout, or is there a explanation and solution for this strange behaviour?
Mininum spacing and margins are set static, only the cellsize is dynamically. And not using dynamic cell size it just works fine.

UICollectionView zoom with scroll.

I'm trying to implement a scrollview where the cells auto zoom as they near a certain point in. As a cell nears the point it will start enlarging and as it moves away - it will shrink. I've been trying to find some tutorials around this but haven't had much luck. Any help would be greatly appreciated.
UICollectionView with a custom layout seems like the right way to do this. A UICollectionViewLayout gets to define the layout attributes for each item, including size and position. All you need to do is define a layout that positions the cells in a grid or however you like, but adjusts the size of the cells according to their distance from the point of interest.
You might find some sample code associated with the collection view talks from WWDC 2012 -- there were some interesting layouts shown there.

TVanimationsGestures Sample code Bug/Weird Behavior Overlapping Cells

Im trying to implement a nice accordion effect on my app. My goal is to "open up" a cell when the user tap on it, diplaying additionnal content (such as text) as the cell height increase.
The perfect sample code for that is the TableView Animations & Gestures sample code provided by Apple. However I am experiencing a strange behavior, that ruins the whole effect.
It appears that depending on the order in which the tableview will display its cells (top --> Bottom or Bottom-->up) the cells textviews will overlap each other or not.
As its a bit difficult to explain with word so here is it with images.
Those screenshots were taken from the TVAnimationsGestures Sample Code, without any changes made to it. It comes from the first version of the sample code without storyboard:
Now the version with the storyboard, first behaved well, but after a while, and without me touching the code it started drawing this :
And I have the exact problem on my custom with my custom cells.
It took me a while to understand what I think the problem comes from. If cells are drawn from the Top cell to the bottom, there is no such problem. However if cells are drawn bottom to the top, they will stack in reverse and therefore overlap each other. I don't think it is possible to control this behavior.
What gave me the hint, is that when I scroll down, forcing the top cell to redraw, they actually redraw nicely, and the screen looks like this:
A Mixture of overlapping cells and "good" cells.
Again, this all comes directly from Apple sample code, without any changes.
Does anyone knows whats going on?
Thanks a lot for your help.
You can increase the cell height by pinching on the cell.

Possible to reuse UILabels on a scrollview?

I'm trying to implement a view that shows a grid of information without using a UITableView, however, since I'm displaying about 36 different statistics, with its label I will have to initialize and use 72 UILabels. Does having so many UILabels mean that my iPhone app's performance will be significantly negatively affected? Is there a way to reuse some of the UILabels to decrease the number of UILabels that must be loaded at one time, or should I just resort to drawing everything on a surface instead?
First of all you should test the interface your thinking of and see if it takes a performance hit. Having a lot of labels all loaded at once will increase your memory footprint but depending on what else is going on in the app, it might not matter.
Secondly, you can't easily reuse the labels but it is possible. However, you would have to constantly monitor the displayed area of the scrollview and move the labels frames around as the view scrolled. I doubt you could do that efficiently. It would take a lot of coding in any case.
Thirdly, any grid like layout can be easily displayed in a table without making it look like a table. For example, the photopicker layout is a table but it looks like a bunch of icons on a white background. Another app I saw used a table to display paragraphs of text but it looked like an ordinary scrolling textview. Every row in a table can be customized to display exactly what you want. In principle, you could use a different cell for every row and they could all be unique in their height and contents.
The advantage of the table is the the table manages what is and is not on screen for you. It does reuse cells and their contents which makes them more efficient. The table also makes it easier to manage a lot of data.