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

boundingRectWithSize:options:attributes:context:

Calculates and returns the bounding rect for the receiver drawn using the given options and display characteristics, within the specified rectangle in the current graphics context. 現在のグラフィック文脈でこの指定された矩形内に、与えられたオプションと表示特徴を使って描画されるレシーバに対する境界rectを計算して返します。

Declaration 宣言

iOS, iPadOS, Mac Catalyst, tvOS, watchOS

- (CGRect)boundingRectWithSize:(CGSize)size 
                       options:(NSStringDrawingOptions)options 
                    attributes:(NSDictionary<NSAttributedStringKey, id> *)attributes 
                       context:(NSStringDrawingContext *)context;

macOS

- (NSRect)boundingRectWithSize:(NSSize)size 
                       options:(NSStringDrawingOptions)options 
                    attributes:(NSDictionary<NSAttributedStringKey, id> *)attributes 
                       context:(NSStringDrawingContext *)context;

Parameters パラメータ

size

The size of the rectangle to draw in. その中に描画することになる矩形の大きさ。

options オプション

String drawing options. 文字列描画オプション。

attributes

A dictionary of text attributes to be applied to the string. These are the same attributes that can be applied to an NSAttributedString object, but in the case of NSString objects, the attributes apply to the entire string, rather than ranges within the string. 文字列に適用されることになるテキスト属性からなる辞書。NSAttributedStringオブジェクトに適用されることができるのと同じ属性があります、しかしNSStringオブジェクトの場合には、属性は文字列全体に適用されます、文字列内の範囲ではなく。

context

The string drawing context to use for the receiver, specifying minimum scale factor and tracking adjustments. レシーバに対して使われることになる文字列描画前後関係、最小限の縮尺率の指定および調節の追随。

Return Value 戻り値

The bounding rect for the receiver drawn using the given options and display characteristics. The rect origin returned from this method is the first glyph origin. 与えられたオプションと表示特徴を使って描画されるレシーバに対する境界rect。このメソッドによって返されるrect原点は、最初のグリフ原点です。

Discussion 議論

To correctly draw and size multi-line text, pass NSStringDrawingUsesLineFragmentOrigin in the options parameter. 複数行テキストを正しく描画および大きさ指定するには、NSStringDrawingUsesLineFragmentOriginをオプションパラメータにおいて渡してください。

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. このメソッドは、小数サイズを返します(返されるCGRectsize構成要素において);返されるサイズを使ってビューをある大きさに作るには、あなたはそれの値を最も近いより高い整数にceil関数を使って持ち上げなければなりません。

This method returns the actual bounds of the glyphs in the string. Some of the glyphs (spaces, for example) are allowed to overlap the layout constraints specified by the size passed in, so in some cases the width value of the size component of the returned CGRect can exceed the width value of the size parameter. このメソッドは、文字列のグリフの実際の境界を返します。グリフのあるもの(例えば、空白)は、渡されるサイズによって指定されるレイアウト制約を上書きすることを許可されます、それでいくつかの場合では返されるCGRectのサイズ構成要素の幅の値はsizeパラメータの幅の値を越えることができます。

See Also 参照

Sizing and Drawing Strings 文字列の大きさ指定と描画