Calculation formula of Cgrectoffset and Cgrectinset

Source: Internet
Author: User

(1) cgrectinset
CGRect Cgrectinset (
CGRect Rect,
CGFloat DX,
cgfloat Dy
);
the application of the structure is centered on the original rect, and then referenced by the Dx,dy to zoom or enlarge.

Examples are as follows:

CGRect r1 = cgrectmake (100, 100, 50, 50);

CGRect R3 = Cgrectinset (r1, 10, 8);//The result should be: 110,108,30,34

/************* calculation works as follows ***************

R1.ORIGIN.X+=DX;//DX is a positive number is + =, negative is =

r1.size.width-=dx*2;

R1.origin.y+=dy;//dy is a positive number is + =, negative is =

r1.size.height-=dy*2;

****/

Apply Result:

r1.origin.x+=10;//Results for: 100+10

r1.size.width-=dx*2;//Results for: 50-10*2

r1.origin.y+=dy;//Results for: 100+8

r1.size.height-=dy*2;//Results for: 50-8*2

Output results

NSLog (@ "cgrectinset=%@\n", Nsstringfromcgrect (R3));

(2) Cgrectoffset
CGRect Cgrectoffset (
cgrect rect,
          CGFloat dx,
          cgfloat dy
offsets relative to the source rectangle Origin rect (the point at the upper-left corner) along the X-and Y-axes, and then on a rect basis along the X-and Y -axes

Examples are as follows:

Float offset =-50.0;

CGRect r1 = cgrectmake (100, 100, 50, 50);

CGRect r2 = cgrectoffset (r1, offset, offset);

/***

R1.origin.x+=offset;

R1.origin.y+=offset;

***/

NSLog (@ "cgrectoffset=%@\n", Nsstringfromcgrect (r2));

Calculation formula of Cgrectoffset and Cgrectinset

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.