LoginSignup
10
12

More than 5 years have passed since last update.

CGRectInset(rect, dx,dy)

Last updated at Posted at 2013-04-19

ちょっと便利

CGRectを中心(center point)を変えずに領域を変更する。

dx,dyの分だけふちがへる。
dx,dyを負にするとふちが膨らむ。

結局
横の長さはdx*2
縦の長さはdy*2
だけ縮まります。

応用例
UItextFieldの文字位置をデフォルトから変えたいときは以下のように調整できます。

rectInsetEx.m
- (CGRect)textRectForBounds:(CGRect)bounds
{
    return CGRectInset(bounds, textOrigin.x, textOrigin.y);
}

- (CGRect)editingRectForBounds:(CGRect)bounds
{
    return CGRectInset(bounds, textOrigin.x, textOrigin.y);
}
10
12
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
12