The difference between frame and bounds in view

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.