CGRectXXX笔记

 

CoreGraphics中有关CGRect相关函数笔记

 

1、CGRectInset

//该结构体的应用是以原rect为中心,再参考dx,dy,进行缩放或者放大。
CGRect rect = CGRectMake(10.0, 10.0, 100.0, 100.0);
CGRect rectToDraw = CGRectInset(rect, 10.0, 10.0);
NSLog(@"==%@", NSStringFromCGRect(rectToDraw));
//结果为:“=={{20.0, 20.0}, {80.0, 80.0}}”

CGRect rect2 = CGRectMake(10.0, 10.0, 100.0, 100.0);
CGRect rectToDraw2 = CGRectInset(rect2, -10.0, -10.0);
NSLog(@"==%@", NSStringFromCGRect(rectToDraw2));
//结果为:“=={{0.0, 0.0}, {120.0, 120.0}}”

  

2、CGRectOffset

//相对于源矩形原点rect(左上角的点)沿x轴和y轴偏移, 再rect基础上沿x轴和y轴偏移
CGRect rect3 = CGRectMake(10.0, 10.0, 100.0, 100.0);
CGRect rectToDraw3 = CGRectOffset(rect3, 12.0, 12.0);
NSLog(@"==%@", NSStringFromCGRect(rectToDraw3));
//结果为:“=={{22.0, 22.0}, {100.0, 100.0}}”

CGRect rect4 = CGRectMake(10.0, 10.0, 100.0, 100.0);
CGRect rectToDraw4 = CGRectOffset(rect4, -12.0, -12.0);
NSLog(@"==%@", NSStringFromCGRect(rectToDraw4));
//结果为:“=={{-2.0, -2.0}, {100.0, 100.0}}”

  

 

posted on 2016-09-29 09:19  流浪_先生  阅读(220)  评论(0编辑  收藏  举报

导航