TwitterTextEditor 1.0.0

TwitterTextEditor 1.0.0

TBXark 维护。



Twitter 文本编辑器

为 iOS 应用提供全功能富文本编辑器的独立、灵活 API。

Twitter Text Editor

这提供强大的文本属性更新逻辑,扩展的文本编辑事件,并易于在基于代理的 API 中处理安全的文本输入事件。TwitterTextEditor 支持最新的 iOS 版本。

要求

Twitter 文本编辑器需 macOS Catalina 10.15 或更高版本和 Xcode 11.0 或更高版本进行开发。目前,Twitter Text Editor 支持 iOS 11.0 或更高版本以及 macCatalyst 13.0 或更高版本。

使用方法

使用 Twitter Text Editor 非常简单。还可以参考示例了解实际用法,其中包含 Swift 和 Objective-C 源代码,以展示如何使用 Twitter Text Editor。请查阅Examples/README.md

将 TwitterTextEditor 框架添加到项目中

将以下行添加到您的 Package.swift 文件中,或者使用 Xcode 的“添加包依赖项…”菜单。

// In your `Package.swift`

dependencies: [
    .package(name: "TwitterTextEditor", url: "https://github.com/twitter/TwitterTextEditor", ...),
    ...
],
targets: [
    .target(
        name: ...,
        dependencies: [
            .product(name: "TwitterTextEditor", package: "TwitterTextEditor"),
            ...
        ]
    ),
    ...
]

与其他依赖项管理工具一起使用

如果你的项目不是使用Swift包管理器,你可以使用Twitter文本编辑器与其他依赖项管理工具一起使用。

CocoaPods

要使用CocoaPods与Twitter文本编辑器,请将下面的添加到你的项目。

Pod::Spec.new do |spec|
  spec.name = "TwitterTextEditor"
  spec.version = "1.0.0" # Find the the version from the Git tags
  spec.authors = ""
  spec.summary = "TwitterTextEditor"
  spec.homepage = "https://github.com/twitter/TwitterTextEditor"
  spec.platform = :ios, "11.0"
  spec.source = {
    :git => "https://github.com/twitter/TwitterTextEditor.git", :tag => "#{spec.version}"
  }
  spec.source_files  = "Sources/TwitterTextEditor/*.swift"
end

然后,更新你项目中的

pod 'TwitterTextEditor', :podspec => 'path/to/TwitterTextEditor.podspec'

Carthage

要使用Carthage与Twitter文本编辑器,请更新你项目的

github "twitter/TwitterTextEditor"

然后,运行以下命令。这将创建Carthage/Build/iOS/TwitterTextEditor.framework

$ carthage update
$ (cd Carthage/Checkouts/TwitterTextEditor && swift package generate-xcodeproj)
$ carthage build --platform iOS

按照说明添加框架和运行脚本阶段到你的项目。

文档

查看文档

在你的项目中使用Twitter文本编辑器

Twitter文本编辑器提供了一个视图,TextEditorView,它具有与UITextView类似的API,并通过属性或简单的委托回调提供大部分功能。

将其添加到你的项目中,就像其他的视图一样,并使用每个属性进行配置,或者实现委托回调。

// In your view controller

import TwitterTextEditor

final class MyViewController: UIViewController {
    // ...

    override func viewDidLoad() {
        super.viewDidLoad()
        // ...
        let textEditorView = TextEditorView()
        textEditorView.text = "Meow"
        textEditorView.textAttributesDelegate = self
        // ...
    }

    // ...
}

extension MyViewController: TextEditorViewTextAttributesDelegate {
    func textEditorView(_ textEditorView: TextEditorView,
                        updateAttributedString attributedString: NSAttributedString,
                        completion: @escaping (NSAttributedString?) -> Void)
    {
        // ...
    }
}

参与贡献

请参阅CONTRIBUTING.md以获取详细信息。

安全问题

请通过Twitter而不是GitHub报告敏感的安全问题。