LineLimitModifier.swift 567 B

12345678910111213141516
  1. extension View {
  2. /// Sets a limit for the number of lines text can occupy in this view.
  3. public func lineLimit(_ limit: Int?, reservesSpace: Bool = false) -> some View {
  4. EnvironmentModifier(self) { environment in
  5. if let limit {
  6. environment
  7. .with(
  8. \.lineLimitSettings,
  9. LineLimit(limit: limit, reservesSpace: reservesSpace)
  10. )
  11. } else {
  12. environment.with(\.lineLimitSettings, nil)
  13. }
  14. }
  15. }
  16. }