A SwiftUI truncation + expand effect for Text:
- Truncates to a fixed number of lines
- Draws a trailing “...More” hint on the last visible line
- Animates expansion by progressively revealing remaining lines with a blur/fade
- iOS 26.0+ (uses SwiftUI
onGeometryChange) - Swift 6.0+
- Xcode 16+ recommended
Note: This implementation currently uses
UIFont, so it’s iOS-focused.
- File → Add Package Dependencies…
- Paste:
https://github.com/telhawasim/TextTruncationEffect.git - Select a version (example:
mainfrom1.0.0) - Add the package to your app target.
dependencies: [
.package(url: "https://github.com/telhawasim/TextTruncationEffect.git", from: "1.0.0")
]import SwiftUI
import TextTruncationEffect
struct DemoView: View {
@State private var isTruncated: Bool = true
let text = "Lorem Ipsum is simply dummy text of the printing and typesetting industry..."
var body: some View {
Text(text)
.font(.caption)
.truncationEffect(length: 2, isEnabled: isTruncated, animation: .smooth(duration: 0.5))
.onTapGesture { isTruncated.toggle() }
.padding(16)
}
}Text.truncationEffect(length: Int, isEnabled: Bool, animation: Animation) -> some Viewlength: number of lines shown when truncation is enabledisEnabled:true= truncated,false= expandedanimation: animation used when toggling
This package is based on the original work/concept demonstrated by Kavsoft:
Note: This project is not affiliated with or endorsed by Kavsoft.
Thanks for your interest in contributing!
- Please do not push directly to
main. - All changes must be submitted via a Pull Request (PR).
- Maintainers will review and approve PRs before merging.
GitHub branch protection is enabled on main, so direct pushes are blocked.
-
Fork the repository
-
Create a new branch from
main:git checkout -b feature/your-change