调用元素.lineLimit(3)
。Text
(从技术上讲,它可以在any View
上调用,在这种情况下,它将限制该视图中所有 Text
元素的行。)
来自SwiftUI.View
:
/// Sets the maximum number of lines that text can occupy in this view.
///
/// The line limit applies to all `Text` instances within this view. 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`.
///
/// - Parameter number: The line limit. If `nil`, no line limit applies.
/// - Returns: A view that limits the number of lines that `Text` instances
/// display.
public func lineLimit(_ number: Int?) -> Self.Modified<_EnvironmentKeyWritingModifier<Int?>>