Skip to main content

Collection View - 2D Display

/*Nothing but dividing items into number of columns and rows */

sizeForItemAtIndexPath()

It returns the size for each item. In collection view, each cell is considered as item and not as rows or columns.
To make it 2D(columns and rows), distribute the collection view frame size into several item sizes, in such a way that x number of items can be placed in a single row.
For instance, if there are 50 items( 5 items in each row which is nothing but 5 columns in 1 row and there are 10 such rows).  Given collection view frame size is 1000.

Now this can be done by dividing the frame size by number of columns,  i.e., 1000/5 = 200. So each items width will be 200.

Comments

Popular posts from this blog

Running Database Fetch (Core Data) in Background Thread using magical Record

   To run database fetching in background thread(in a separate context), so that the UI does not get blocked: __block NSMutableArray *dataArray= [[NSMutableArray alloc] init];   // Create a child context of the main context   NSManagedObjectContext *privateContext = [NSManagedObjectContext MR_context];   // When using private contexts execute the core data code in it's private queue using performBlock: or performBlockAndWait:   [privateContext performBlock:^{     // Execute fetch   NSArray *privateObjects;   if(entity_predicate == nil) {       //fetch all! duh!       privateObjects = [self MR_findAllSortedBy:sort_key ascending:YES inContext:privateContext];     } else {       privateObjects = [self MR_findAllSortedBy:sort_key ascending:YES withPredicate:entity_predicate inContext:privateContext];   ...

Percent Escape the reserved Characters in URI

URI encoding need to be done when performing network API calls based on RFC 3986. In order to encode any character, the following native method can be used: [uriString stringByAddingPercentEncodingWithAllowedCharacters : [ NSCharacterSet URLQueryAllowedCharacterSet ] ] But the above method is not compliant with RFC3986 and it does not encode the reserved characters like "!*'();:@&=+$,/?%#[]". Hence, the following method can be used for percent encoding the specific reserved characters. ((NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(NULL, (__bridge CFStringRef) string, NULL,  CFSTR("!*'();:@&=+$,/?%#[]"), encoding))); }

Unity Upgrade 2017.2 and above

Hello  Unity Developers , Recently, I faced few issues with Unity Editor and I hope sharing it will help. What was I trying to do? Scenario? Upgrading to Unity 2017.2 & Unity 2017.3 I was trying to upgrade one of my project from Unity 2017.1.2 version to Unity 2017.2.1f1. On doing so, usually unity automatically updates the obsolete scripts to support new APIs. Once it got updated, I tried to play the game in editor and it worked. Then, what was the problem? While building the project to UWP application, there were some compile errors where Unity.VR need to be updated to Unity.XR. I fixed those errors, quit unity and tried building again.  Wait, Why did I quit Unity and then built it again? Its because unity has this weird issue, when there are compiler errors. Though I had fixed the errors, on building it again, the errors will not go away. We have to quit unity and then build it, TADA, the error will go away. Now coming back to other is...