LoginSignup
12
12

More than 5 years have passed since last update.

boundingRectWithSize:options:attributes:context: でサイズ計算したら文字が切れると思ったら。

Last updated at Posted at 2014-03-15

公式ドキュメント

This method returns fractional sizes (in the size component of the returned CGRect); to use a returned size to size views, you must raise its value to the nearest higher integer using the ceil function.

って書いてあった。
なのでよしなに ceil する。

    CGRect calcRect = [str boundingRectWithSize:CGSizeMake(maxWidth, maxHeight)
                                       options:NSStringDrawingUsesLineFragmentOrigin
                                    attributes:@{NSFontAttributeName : font}
                                       context:nil];
    return CGRectMake( x, y,
                      ceil( calcRect.size.width ), ceil( calcRect.size.height ));
12
12
0

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
12
12