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

drawInRect:withAttributes:

Draws the attributed string inside the specified bounding rectangle. 属性付き文字列をこの指定された境界矩形の内側に描画します。

Declaration 宣言

iOS, iPadOS, Mac Catalyst, tvOS, watchOS

- (void)drawInRect:(CGRect)rect 
    withAttributes:(NSDictionary<NSAttributedStringKey, id> *)attrs;

macOS

- (void)drawInRect:(NSRect)rect 
    withAttributes:(NSDictionary<NSAttributedStringKey, id> *)attrs;

Parameters パラメータ

rect

The bounding rectangle in which to draw the string. In AppKit, the origin of the bounding box is normally in the lower-left corner, but the origin is in the upper-left corner if the focused view is flipped. それの中に文字列を描画することになる境界矩形。AppKitでは、境界ボックスの原点は普通は下左隅です、しかし原点はもしフォーカスされたビューがフリップされたならば上左隅です。

attrs

The text attributes with which to draw 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オブジェクトの場合には、属性は文字列全体に適用されます、文字列内の範囲ではなく。

Discussion 議論

This method draws as much of the string as it can inside the specified rectangle, wrapping the string text as needed to make it fit. If the string is too long to fit inside the rectangle, the method renders as much as possible and clips the rest. このメソッドは、多くの文字列をそれがその指定された矩形内部に可能なだけ描画して、文字列テキストを必要に応じてそれがぴったり収まるようにワードラップしています。文字列が矩形にぴったり収まるには大きすぎるならば、メソッドは可能な限りたくさん描画して、残りを切り取ります。

If newline characters are present in the string, those characters are honored and cause subsequent text to be placed on the next line underneath the starting point. 改行文字が文字列において存在するならば、それら文字は尊重されます、そして続くテキストが、開始点の真下の次の行上に置かれるようにします。

There must be either a focused view or an active graphics context when you call this method. あなたがこのメソッドを呼び出す場合、フォーカスされたビューまたはある実際のグラフィックコンテキストのどちらかがなければなりません。

See Also 参照

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