View's bounds default is (0,0,self.frame.size.width,self.frame.size.height)
The location of the view is determined by view.frame, and View.bounds determines the origin of its child view . Write an example and you'll see.
1- (void) Viewdidload {2 [Super Viewdidload];3Self.view.backgroundColor =[Uicolor Lightgraycolor];4 [self setupallback];5 }6 7-(void) setupallback{8UIView *view1 = [[UIView alloc] Initwithframe:cgrectmake ( -, -,280, -)];9View1.bounds = CGRectMake (- -, - -,280, -);TenView1.backgroundcolor =[Uicolor Redcolor]; One[Self.view Addsubview:view1];//Add to Self.view ANSLog (@"view1 frame:%@========view1 bounds:%@", Nsstringfromcgrect (View1.frame), Nsstringfromcgrect (View1.bounds)); - -UIView *view2 = [[UIView alloc] Initwithframe:cgrectmake (0,0, -, -)]; theView2.backgroundcolor =[Uicolor Browncolor]; -[View1 ADDSUBVIEW:VIEW2];//add to View1, at which point the upper-left corner of the View1 coordinate system starts with ( -20,-20) -NSLog (@"view2 frame:%@========view2 bounds:%@", Nsstringfromcgrect (View2.frame), Nsstringfromcgrect (View2.bounds)); -}
Printing results are:
2015-07-21 13:23:20.941 Demo-frame and bounds differences [2147:87996] view1 frame:{{20, +}, {280, 250}}========view1 bounds:{{-20,- 20}, {280, 250}}
2015-07-21 13:23:20.942 Demo-frame and bounds differences [2147:87996] View2 frame:{{0, 0}, {100}}========view2 bounds:{{0, 0}, { 100, 100}}
The above demo is shown below:
Because the VIEW2 is drawn at the origin (0,0) of the View1, and the origin of View1 is ( -20,-20), VIEW2 will move 20 units down and to the right to meet the VIEW2 requirements.
The difference between frame and bounds in view