- iOS 15+
- SwiftUI & UIKit
- SwiftPackageManager
var more: NSMutableAttributedString{
let more = NSMutableAttributedString(string: " ... ")
more.append(NSAttributedString(
string: "더보기",
attributes: [
.font: UIFont.systemFont(ofSize: 14, weight: .light),
.foregroundColor: UIColor.red,
.underlineStyle: NSUnderlineStyle.single.rawValue
]
))
return more
}
ReadMoreText("""
✔️👩👩👦👦Hello World(Hello World) Hello WorldHello WorldHello World❣️👩⚖👩👩👦👦
✔️Hello World✨
✔️Hello WorldHello WorldHello WorldHello WorldHello World
✔️Hello World Hello World Hello World(Hello World or Hello World)Hello World
✔️’Hello World’ Hello World
✔️Hello World⚠️ Hello WorldHello WorldHello World!
""", // original text
isExpanded: $expanded
) // Binding을 이용해서 외부에서 접기/펼치기 핸들링
.applyAnimation(nil) // 펼침/접기 animation
.textContainerInset(.zero) // UITextView 속성
.lineFragmentPadding(0) // UITextView 속성
.typography(.convertToUIFont(.body1, weight: .bold), .black) // 원문 텍스트에 Pretendard 폰트 적용
.moreText(more) // 더보기 텍스트에 NSAttributedString 적용
.trimText(AttributedString("접기")) // 접기 텍스트에 AttributedString 적용
.lineLimit(3) // 3줄 이상일 경우 더보기 노출