Skip to content

Instantly share code, notes, and snippets.

@jbasinger
Created March 23, 2017 17:37
Show Gist options
  • Save jbasinger/303d0d007164bc33e89dceff73df149c to your computer and use it in GitHub Desktop.
Save jbasinger/303d0d007164bc33e89dceff73df149c to your computer and use it in GitHub Desktop.
A function that'll throw a label on a cell with it's index path. Useful for debugging weird layouts.
-(void)showIndexPath:(NSIndexPath*)indexPath inView:(UIView*)view{
UILabel *lbl = [[UILabel alloc] init];
lbl.text = [NSString stringWithFormat:@"%ld-%ld", (NSUInteger)indexPath.section, (NSUInteger)indexPath.item];
lbl.font = [UIFont systemFontOfSize:8.f];
lbl.numberOfLines = 0;
lbl.backgroundColor = [UIColor blackColor];
lbl.textColor = [UIColor whiteColor];
[lbl sizeToFit];
[view addSubview:lbl];
NSMutableArray *constraints = [NSMutableArray array];
[constraints addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-[lbl(10)]" options:NSLayoutFormatAlignAllLeft metrics:nil views:@{@"lbl":lbl}]];
[constraints addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[lbl(10)]-|" options:NSLayoutFormatAlignAllLeft metrics:nil views:@{@"lbl":lbl}]];
[NSLayoutConstraint activateConstraints:constraints];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment