0

I have a "frame within a frame" scenario. There is a 600x600 area inside of the main screen. What I would like to do is to just color the 600x600 area so that I can visualize where I am working. I have tried using self.backgroundColor = [UIColor whiteColor]; but that colors the whole screen instead of just the 600x600 area.

What would be the best way to color the background of the 600x600 area?

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame: CGRectMake(84, 0, 600, 600)];
    if (self) {
        //initialization code
        tileArray = [[NSMutableArray alloc]initWithCapacity: 9];

        tile1 = [[TileView alloc]
                 initWithFrame:CGRectMake(100, 100, 128, 128)
                 withImageNamed:@"Yellow1.png"];

        [self addSubview:tile1];

        int x = [self frame].size.width;
        int y = [self frame].size.width;
        NSLog(@" Width: %i. Height: %i.", x,y);
    }
    return self;
}
Lorenzo B
  • 33,216
  • 24
  • 116
  • 190
joshft91
  • 1,755
  • 7
  • 38
  • 53
  • 1
    What about setting `self.backgroundColor = [UIColor redColor];`? Does the color cover the entire screen? – Lorenzo B Feb 21 '13 at 21:22
  • Sorry, I should have used a better example. When I change it to `self.backgroundColor = [UIColor redColor];` the whole background is red instead. – joshft91 Feb 21 '13 at 21:41
  • SO, is this the same behavior of the previous example? – Lorenzo B Feb 21 '13 at 21:46
  • Yeah. I'm very new to Objective-C, but would self refer to the "new" self referring to the 600x600 area? – joshft91 Feb 21 '13 at 21:48
  • Sorry, I cannot understand what you mean. – Lorenzo B Feb 21 '13 at 21:55
  • If I'm understanding this correct, self should now refer to the new 600x600 frame, correct? `self = [super initWithFrame: CGRectMake(84, 0, 600, 600)];` – joshft91 Feb 21 '13 at 22:02
  • Sure, `self` is the same as `this` (like in C#). It refers to the current instance. – Lorenzo B Feb 21 '13 at 22:03
  • I really suggest to read http://stackoverflow.com/questions/5361369/ios-programming-frame-bounds-and-center/11282765#11282765. This is my answer to understand views. Hope that helps. – Lorenzo B Feb 21 '13 at 22:08

0 Answers0