Closed xiaoxidong closed 3 years ago
HLTE never meant to support paragraph styles, so marking this as a feature request.
I take it back. .paragraphStyle
is on NSAttributedString.Key
, so you can actually do this already.
let all = try! NSRegularExpression(pattern: "^.*$", options: [.dotMatchesLineSeparators])
struct ContentView: View {
@State private var text: String = "**bold** \nline two"
var body: some View {
VStack {
HighlightedTextEditor(text: $text, highlightRules: [
HighlightRule(pattern: all, formattingRule: TextFormattingRule(key: .paragraphStyle, value: grafStyle))
])
}
}
private var grafStyle: NSParagraphStyle {
let style = NSMutableParagraphStyle()
style.lineSpacing = 20
style.paragraphSpacing = 40
return style
}
}
Thank you so much, I am new to swift and learning swiftUI. Really help me a lot.
No problem! Happy to help, everybody has to start somewhere.
I want to change the paragraph spacing and line spacing, and I set the defaultParagraphStyle for the textView, but it seems not working. Here is the code add to the textView.
Thank you so much.