ResizingTextView

3.0.0

A (non)selectable, single-line/multi-line, (non)self-sizing, (non)scrollable, (un)editable text view for iOS and macOS.
mshibanami/ResizingTextView

What's New

2024-05-06T13:49:53Z

The version 2.1.0 has a bug that removes the default padding of an editable text view. Now, the default 8pt vertical padding has been restored.

Some users might already be working around this bug, so to avoid disrupting their solutions, I have incremented the major version.

If you're updating from 2.0.0 or earlier, this release shouldn't cause any breaking changes.

ResizingTextView

This is a SwiftUI resizing text view for iOS and macOS.

Usage

// Self-sizing automatically (Default)
ResizingTextView(text: $text1)

// Fixed height, scrollable, newline characters not allowed
ResizingTextView(
    text: $text2,
    placeholder: "Placeholder",
    isScrollable: true,
    canHaveNewLineCharacters: false
)
.frame(height: 80)

// Uneditable, selectable, color/font changed
ResizingTextView(
    text: $text3,
    isEditable: false
)
.font(.boldSystemFont(ofSize: 16))
.foregroundColor(.magenta)

// Uneditable, selectable, max 2 lines
ResizingTextView(
    text: .constant("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."),
    isEditable: false,
    lineLimit: 2
)

// Uneditable, unselectable, max 2 lines
ResizingTextView(
    text: .constant("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."),
    isEditable: false,
    isSelectable: false,
    lineLimit: 2
)

// Selectable, uneditable, non greedy
ResizingTextView(
    text: .constant("Lorem ipsum"),
    isEditable: false,
    hasGreedyWidth: false
)
.background(.yellow)

#if os(iOS)
// No autocapitalization (iOS Only)
ResizingTextView(
    text: $text4,
    placeholder: "Placeholder"
)
.autocapitalizationType(.none)
#endif

// Customized textContentInset
ResizingTextView(
    text: $text5,
    placeholder: ""
)
#if os(macOS)
.textContainerInset(CGSize(width: 40, height: 10))
#elseif os(iOS)
.textContainerInset(UIEdgeInsets(top: 0, left: 40, bottom: 0, right: 40))
#endif
}

Demo

iOS

Screen.Recording.2022-08-14.at.6.35.55.pm.mov

macOS

Screen.Recording.2022-08-14.at.6.33.57.pm.mov

Apps that use this package

Description

  • Swift Tools 5.6.0
View More Packages from this Author

Dependencies

  • None
Last updated: Fri Oct 18 2024 19:11:53 GMT-0900 (Hawaii-Aleutian Daylight Time)