Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change Cell Size ( or number of items in one column) #4

Closed
chlebta opened this issue Mar 13, 2015 · 7 comments
Closed

Change Cell Size ( or number of items in one column) #4

chlebta opened this issue Mar 13, 2015 · 7 comments

Comments

@chlebta
Copy link

chlebta commented Mar 13, 2015

Hello, thank's this really simple and great Library and I need to know how can I change the cells size and use my costum size.
Also I've noticed that the number of cells in rows is always multiplier of 2 (2 cells, 4 cells, 8 cells ... in a row) and the big cell size is 2 cells for width and height.
So it will be more nicer if you allows user to define the number of cell in row and the big cell size (for example 3cell for height and 4 for width).
Also I'm ready to contribute in this project

@JVillella
Copy link
Contributor

Hey there @chlebta you are right about the cell column counts being multiples of 2. More information about how the algorithm works can be found on the blog post I've linked from the README. This multiples of 2 behaviour goes hand in hand with the layout algorithm and changing it to something else would require a different process.

Now about the column sizes - they can be changed by implementing collectionView:layout:numberOfColumnsInSection: in the FMMosiacLayoutDelegate. Higher column counts mean smaller cell width.

Happy coding!

@chlebta
Copy link
Author

chlebta commented Mar 14, 2015

@JVillella This Will change the height from small to double the height of small cell thats all but i want to use custom height and width. Also the blog link doesn't work .
This is Example what of I I'm talking about :
capture d ecran 2015-03-14 a 10 55 44

*So the screen will be divide into 3 column.
*Each column will hold one items.
*the big cell items size will be the double.

I'm new on objective and IOS world but Algorithm and mathematic I got great skills, so if you don't mind we can work's on optimizing this library ?

@JVillella
Copy link
Contributor

I see what your saying. Many of us would benefit from more customizable mosaic sizing. If you'd like to try some experiments and see what you can do - that would be awesome! I think the site is up now, give it another try.

@chlebta
Copy link
Author

chlebta commented Mar 14, 2015

@JVillella Yes the site work's now and I'm will give try to optimize this library and make it more simple and customizable 👍 also can I get your email to talk directly and in case of trouble.

@JVillella
Copy link
Contributor

That would be great thanks! My email is in the podspec of the repo's root. So that others can learn from your progress it may be best to keep our chats on this thread. I reply quickly either way.

@chlebta
Copy link
Author

chlebta commented Mar 17, 2015

@JVillella Hello, is there any rapid hack to add third type of Cell (where width = 2*Small Cell width ; and height = normal small Cell height) ?
Also can you make the code more commented I'm working on solution to make it more dynamic as we talked .

@JVillella
Copy link
Contributor

The algorithm asks the FMMosaicLayoutDelegate for the type of mosaic cell size (either FMMosaicCellSizeBig, or FMMosaicCellSizeSmall - half the size of big). This is done in:

- (FMMosaicCellSize)collectionView:(UICollectionView *)collectionView
                            layout:(FMMosaicLayout *)collectionViewLayout
  mosaicCellSizeForItemAtIndexPath:(NSIndexPath *)indexPath;

We work in columns, which again is provided by the delegate in:

- (NSInteger)collectionView:(UICollectionView *)collectionView
                     layout:(FMMosaicLayout *)collectionViewLayout
   numberOfColumnsInSection:(NSInteger)section;

We use a buffer to store small cells until we have 2 (enough to fill the width of a column). This is when we actually add it to our column heights array property (currently named columnHeightsInSection) and our layout attributes property (currently named layoutAttributes).

If we have leftover small cells after this process (because there weren't 2 to pair together) we handle them separately (see the commented code block about this).

The column heights property maintains the height of each column in each section. It's a 2D array - an array of sections, and heights per column in each section.

The majority of the rest of code deals with UICollectionViewLayout specifics. You said you were new to iOS and Objective-C. A book that helped me understand them better when I was learning was iOS UICollectionView: The Complete Guide as well as this article about combining UICollectionView and UIDynamics. It goes a lot into how the layouts work. Both resources are written by @ashfurrow.


there any rapid hack to add third type of Cell (where width = 2*Small Cell width; and height = normal small Cell height)?

Yes this can be done. It's relatively similar to how the small cells are buffered and then added to those two properties (cell heights array, layout attributes). This shouldn't be hard to do - probably a few lines.

Good luck. Hope that helps!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants