Instance Method インスタンスメソッド

boundingRect(with:options:context:)

Returns the bounding rectangle necessary to draw the string. この文字列を描画するのに必要な境界矩形を返します。

Declaration 宣言

iOS, iPadOS, Mac Catalyst, tvOS, watchOS

func boundingRect(with size: CGSize, 
          options: NSStringDrawingOptions = [], 
          context: NSStringDrawingContext?) -> CGRect

macOS

func boundingRect(with size: NSSize, 
          options: NSString.DrawingOptions = [], 
          context: NSStringDrawingContext?) -> NSRect

Parameters パラメータ

size

The width and height constraints to apply when computing the string’s bounding rectangle. 文字列の持つ境界矩形を計算する場合に適用することになる幅と高さ制約。

options オプション

Additional drawing options to apply to the string during rendering. レンダリングの間に文字列に適用することになる追加の描画オプション。 For a list of possible values, see NSString.DrawingOptions.

context

A context object with information about how to adjust the font tracking and scaling information. On return, the specified object contains information about the actual values used to render the string. This parameter may be nil. どのようにフォントのトラッキングおよびスケーリング情報を調整するかについての情報を持つコンテキストオブジェクト。戻りにおいて、この指定されたオブジェクトは、文字列を描出するのに使われる実際の値についての情報を含みます。このパラメータはnilであるかもしれません。

Return Value 戻り値

A rectangle whose size component indicates the width and height required to draw the entire contents of the string. それのサイズ構成要素がこの文字列の全内容を描画するのに必要とされる幅と高さを指し示す矩形。

Discussion 議論

You can use this method to compute the space required to draw the string. The constraints you specify in the size parameter are a guide for the renderer for how to size the string. However, the actual bounding rectangle returned by this method can be larger than the constraints if additional space is needed to render the entire string. Typically, the renderer preserves the width constraint and adjusts the height constraint as needed. あなたは、このメソッドを使って文字列を描画するのに必要とされる空間を計算することができます。あなたがサイズパラメータにおいて指定する制約は、どのように文字列をある大きさに作るかについてのレンダラーに対する指針です。しかしながら、このメソッドによって返される実際の境界矩形は、制約よりも大きいことがあります、もし追加的空間が文字列全体を描出するのに必要とされるならば。概して、レンダラーは幅制約を保全して、高さ制約を必要に応じて調節します。

In iOS 7 and later, this method returns fractional sizes (in the size component of the returned rectangle); to use a returned size to size views, you must use raise its value to the nearest higher integer using the ceil function. iOS 7以降において、このメソッドは小数サイズを返します(返される矩形のsize構成要素において);返されるサイズを使ってビューをある大きさに作るには、あなたはそれの値を最も近いより高い整数にceil関数を使って持ち上げなければなりません。

Special Considerations 特別な注意事項

To calculate the bounding rectangle, this method uses the baseline origin by default, so it behaves as a single line. To render the string in multiple lines, specify usesLineFragmentOrigin in options. 境界矩形を計算するために、このメソッドはベースライン原点を初期状態で使います、それでそれは単一の行として振舞います。文字列を複数の行で描出するには、usesLineFragmentOriginoptionsにおいて指定してください。

See Also 参照

Getting Metrics for the String 文字列に対する寸法を得る