(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