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

lineLimit(_:)

Sets the maximum number of lines that text can occupy in this view. 最大限の行数を設定します、それはテキストがこのビューにおいて占めることができるものです。

Declaration 宣言

func lineLimit(_ number: Int?) -> some View

Return Value 戻り値

A view that limits the number of lines that Text instances display. あるビュー、それはTextインスタンスが表示する行数を制限します。

Parameters パラメータ

number

The line limit. If nil, no line limit applies. 行限度。nilならば、行限度は適用されません。

Discussion 議論

Use lineLimit(_:) to cap the number of lines that an individual text element can display.

The line limit applies to all Text instances within a hierarchy. For example, an HStack with multiple pieces of text longer than three lines caps each piece of text to three lines rather than capping the total number of lines across the HStack. 例えば、3行より長いテキストの断片を複数もつHStackは、テキストの各断片を3行に制限します、HStack全体にわたる行の総数を制限するのではなく。

In the example below, the lineLimit(_:) operator limits the very long line in the Text element to the 2 lines that fit within the view’s bounds:


Text("This is a long string that demonstrates the effect of SwiftUI's lineLimit(:_) operator.")
 .frame(width: 200, height: 200, alignment: .leading)
 .lineLimit(2)

A screenshot showing showing the effect of the line limit operator on

See Also 参照

Handling Multiline Text 複数行テキストを取り扱う