一个类似于 TextEditor
的增强版本,旨在保持其在 iOS 和 macOS 平台上的使用一致性。
✦ 我的 macOS/iOS 应用程序 ✦
您可以通过将其作为包依赖项添加到 Xcode 项目中来添加 MarkdownUI。
Markdown
链接到您的应用程序目标或将以下内容添加到 Package.swift
.package(url: "https://github.com/jaywcjlove/swiftui-texteditor", from: "1.0.0")
或者 在 Xcode 中添加包。
import TextEditorPlus
struct ContentView: View {
@State var text = """
Hello World
"""
@State var isEditable = true
var body: some View {
TextEditorPlus(text: $text)
.textSetting(isEditable, for: .isEditable)
}
}
设置文本粗细和大小
TextEditorPlus(text: $text)
.font(.systemFont(ofSize: 24, weight: .regular))
设置编辑器内边距
TextEditorPlus(text: $text)
.textSetting(23, for: .insetPadding)
设置编辑器背景颜色
TextEditorPlus(text: $text)
.textSetting(NSColor.red, for: .backgroundColor)
设置编辑器文本颜色
TextEditorPlus(text: $text)
.textSetting(NSColor.red, for: .textColor)
设置编辑器占位符字符串
TextEditorPlus(text: $text)
//.font(NSFont(name: "pencontrol", size: 12)!)
.font(.systemFont(ofSize: CGFloat(Float(fontSize)!), weight: .regular))
.textSetting("Test placeholder string", for: .placeholderString)
使用属性(例如视觉样式、超链接或文本部分的辅助功能数据)来操作带属性的字符串。
TextEditorPlus(text: $text)
.textSetting(isEditable, for: .isEditable)
.textViewAttributedString(action: { val in
let style = NSMutableParagraphStyle()
style.lineSpacing = 5
style.lineHeightMultiple = 1.2
val.addAttribute(.paragraphStyle, value: style, range: NSRange(location: 0, length: val.length))
return val
})
根据 MIT 许可证获得许可。