In viewDidLoad
, I create a UIView
at 100,100 with a size of 200x200, then change it's bounds to have an origin of -100,-100. I had supposed that this would either move the entire view back to the top left, or only draw a smaller rectangle for the intersection of the frame and bounds. It didn't affect the drawn-into area at all.
- (void)viewDidLoad
{
[super viewDidLoad];
CGRect rect = CGRectMake(100, 100, 200, 200);
greenView = [[UIView alloc] initWithFrame:rect];
[greenView setBackgroundColor:[UIColor greenColor]];
CGRect bounds = CGRectMake(-100, -100, 200, 200);
[greenView setBounds:bounds];
[greenView setClipsToBounds:YES];
[greenView setContentMode:UIViewContentModeRedraw];
[self.view addSubview:greenView];
}
The frame and bounds log as follows:
Frame: {{100, 100}, {200, 200}}
Bounds: {{-100, -100}, {200, 200}}
I thought that a view only draws into it's bounds rect. What am I missing about views and bounds? Why doesn't changing my view's bounds change where it draws?
Here's what it looks like: