CGRectmake problems

Discussion in 'iOS Programming' started by blue-lion, Oct 15, 2011.

  1. blue-lion, Oct 15, 2011
    Last edited by a moderator: Oct 15, 2011

    blue-lion macrumors member

    Jan 26, 2010
    I'm really struggling to understand the CGRectMake. I understand its the position of the start and size of the rectangle, but i keep seeing examples where the X and Y positioning are always 0,0 . When i would expect different objects on a view to be positioned differently all all over screen ?. sorry if this is pretty basic stuff. The example beneath is has a header and footer sections both positioned at X0 and Y0 ,when i would have thought the footer would be down the screen with a higher Y value?

    are the numbers relative to the view that contains the object ?, even so, i still don't really get it?

    please help

    // setup our table data
    	self.tableArray = [NSArray arrayWithObjects:@"Camping", @"Water Skiing", @"Weight Lifting", @"Stamp Collecting", nil];
    	// set up the table's header view based on our UIView 'myHeaderView' outlet
    	CGRect newFrame = CGRectMake(0.0, 0.0, self.tableView.bounds.size.width, self.myHeaderView.frame.size.height);
    	self.myHeaderView.backgroundColor = [UIColor clearColor];
    	self.myHeaderView.frame = newFrame;
    	self.tableView.tableHeaderView = self.myHeaderView;	// note this will override UITableView's 'sectionHeaderHeight' property
    	// set up the table's footer view based on our UIView 'myFooterView' outlet
    	newFrame = CGRectMake(0.0, 0.0, self.tableView.bounds.size.width, self.myFooterView.frame.size.height);
    	self.myFooterView.backgroundColor = [UIColor clearColor];
    	self.myFooterView.frame = newFrame;
    	self.tableView.tableFooterView = self.myFooterView;	// note this will override UITableView's 'sectionFooterHeight' property
  2. jiminaus macrumors 65816


    Dec 16, 2010
    How a CGRect is interpreted depends on what property it's assigned to or read from. Read the details on the frame and the bounds properties in the UIView class reference.
  3. xStep macrumors 68000

    Jan 28, 2003
    Less lost in L.A.

Share This Page