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

draw(with:options:context:)

Draws the attributed string in the specified bounding rectangle using the provided options. 属性付文字列をこの指定された境界矩形の内側にその提供されたオプションを使って描画します。

Declaration 宣言

iOS, iPadOS, Mac Catalyst, tvOS, watchOS

func draw(with rect: CGRect, 
  options: NSStringDrawingOptions = [], 
  context: NSStringDrawingContext?)

macOS

func draw(with rect: NSRect, 
  options: NSString.DrawingOptions = [], 
  context: NSStringDrawingContext?)

Parameters パラメータ

rect

The bounding rectangle in which to draw the string. それの中に文字列を描画することになる境界矩形。

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であるかもしれません。

Discussion 議論

If usesLineFragmentOrigin is specified in options, it wraps the string text as needed to make it fit. If the string is too big to fit completely inside the rectangle, the method scales the font or adjusts the letter spacing to make the string fit within the given bounds. usesLineFragmentOriginoptionsにおいて指定されるならば、それは一連なりのテキストを必要に応じてワードラップして、それが収まるようにします。文字列が矩形内に完全に収まるには大きすぎるならば、メソッドはフォントを縮尺するまたは文字の間隔を調整して、文字列をこの与えられた境界内に収まるようにします。

If usesLineFragmentOrigin is not specified in options, the origin of the rectangle is the baseline of the only line. The text will be displayed above the rectangle and not inside of it. For example, if you specify a rectangle starting at 0,0 and draw the string ‘juxtaposed’, only the descenders of the ‘j’ and ‘p’ will be seen. The rest of the text will be on the top edge of the rectangle. usesLineFragmentOriginoptionsにおいて指定されないならば、矩形の原点がその唯一の行のベースラインです。テキストは、矩形の上に表示されるでしょう、それの内側でなしに。例えば、あなたが0,0で開始する矩形を指定して文字列 ‘juxtaposed’ を描画するならば、 ‘j’ と ‘p’ のデセンダーだけが見られるでしょう。テキストの残りは、矩形の上端の上にあるでしょう。

This method draws the line using the attributes specified in the attributed string itself. 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 an active graphics context when you call this method. あなたがこのメソッドを呼び出す場合、どれか1つ実際のグラフィックコンテキストがなければなりません。

Special Considerations 特別な注意事項

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

See Also 参照

Drawing the String 文字列を描画する