Created
March 23, 2017 17:37
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(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