Wednesday, May 11, 2011

Visual UI Debugging

Sometimes you need to debug location of objects. This can be difficult, when those objects are transparent or have same color as the background.

One way is to print view frame into console:
NSLog(@"%@", NSStringFromCGRect(frame));
2011-05-11 06:54:19.257 MyApp[10030:40b] [Line 10] {{0, 0}, {320, 30}}
...but sometimes it's easier and faster to just take a good look at objects. You can do this with temporary debug code:
label.backgroundColor = [UIColor redColor];
label.layer.borderColor = [[UIColor cyanColor] CGColor];
label.layer.borderWidth = 2;

2 comments:

  1. I have definitely made use of "backgroundColor = [UIColor redColor]" multiple times when trying to lay out something just right!

    ReplyDelete
  2. I found random color addition to uicolor handy while debugging.

    Pls refer http://www.cocoanetics.com/2011/05/visual-view-debugging/

    ReplyDelete