首页 > 代码库 > CGRectInset vs CGRectOffset

CGRectInset vs CGRectOffset

1.CGRectInset

CGRect CGRectInset (
   CGRect rect,
   CGFloat dx,
   CGFloat dy
);

return rect which is smaller or larger than the source with the same center point

CGFloat x,y,width,height,d_x,d_y;
CGRect  rect = CGRectMake(x,y,width,height); //the origin frame
CGRect  n_rect = CGRectInset(rect, d_x, d_y);       //the new frame

n_rect.x = x + d_x; 
n_rect.y = y + d_y; 
n_rect.size.width = width - 2 * d_x; 
n_rect.size.height = height- 2 * d_y; 

offset dx,dy,adjust size by (2dx,2dy).
If the two rectangles do not intersect, returns the null rectangle.