2013年3月11日 星期一

- drawRect: CGRectInset

最近用到了一個指令
CGRectInset(CGRect rect, CGFloat dx, CGFloat dy)
老是搞不清楚運作的方式
所以做了個實驗並將果記錄下來

rect = (0, 0 ,320, 480)
     
     CGRectInset(rect, 0, 0)    =>    x = 0.000000,   y = 0.000000,   width = 320.000000, height = 480.000000
     CGRectInset(rect, 10, 0)   =>    x = 10.000000,  y = 10.000000,  width = 300.000000, height = 480.000000
     CGRectInset(rect, 20, 0)   =>    x = 20.000000,  y = 20.000000,  width = 280.000000, height = 480.000000
     CGRectInset(rect, 0, 10)   =>    x = 0.000000,   y = 0.000000,   width = 320.000000, height = 460.000000
     CGRectInset(rect, 0, 20)   =>    x = 0.000000,   y = 0.000000,   width = 320.000000, height = 440.000000
     CGRectInset(rect, 10, 20)  =>    x = 10.000000,  y = 10.000000,  width = 300.000000, height = 440.000000
    
     CGRect newRect = CGRectInset(CGRect rect, CGFloat dx, CGFloat dy)
     
     newRect.origin.x = dx;
     newRect.origin.y = dx;
     newRect.size.width = rect.size.wide - dy * 2
     newRect.size.height = rect.size.height - dy * 2

沒有留言:

張貼留言