Skip to content

Instantly share code, notes, and snippets.

@scompt
Last active December 18, 2015 20:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scompt/5841542 to your computer and use it in GitHub Desktop.
Save scompt/5841542 to your computer and use it in GitHub Desktop.
A code snippet to visualize the placement of cells in a UICollectionViewLayout. Stick it at the bottom of the layoutAttributesForElementsInRect: method and copy/paste the output in your terminal window and you'll something like this: http://i.imgur.com/X74mB0v.png.
NSMutableString *magick = [[NSMutableString alloc] init];
[magick appendString:@"xc:skyblue -fill white -stroke black "];
int minX = rect.origin.x;
int minY = rect.origin.y;
int maxX = rect.size.width;
int maxY = rect.size.height;
for (UICollectionViewLayoutAttributes *att in theLayoutAttributes) {
minX = MIN(minX, att.frame.origin.x);
minY = MIN(minY, att.frame.origin.y);
maxX = MAX(maxX, att.frame.origin.x + att.frame.size.width);
maxY = MAX(maxY, att.frame.origin.y + att.frame.size.height);
int page = att.indexPath.row / self.perPage;
[magick appendFormat:@" -draw \"rectangle %.0f,%.0f %.0f,%.0f\" -draw \"text %.0f,%.0f '%d/%d'\"", att.frame.origin.x, att.frame.origin.y, att.frame.origin.x + att.frame.size.width, att.frame.origin.y + att.frame.size.height, att.frame.origin.x, att.frame.origin.y, att.indexPath.item, page];
}
[magick insertString:[NSString stringWithFormat:@"convert -size %dx%d ", maxX, maxY] atIndex:0];
[magick appendFormat:@" -fill none -stroke red -draw \"rectangle %.0f,%.0f %.0f,%.0f\"", rect.origin.x, rect.origin.y, rect.origin.x+rect.size.width, rect.origin.y+rect.size.height];
[magick appendFormat:@" -crop %.0fx%.0f+%.0f+%.0f +repage", rect.size.width+10, rect.size.height+10, rect.origin.x-5, rect.origin.y-5];
static int count = 0;
[magick appendFormat: @" blah%04d.png", count++];
NSLog(@"magick: %@", magick);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment