ruddfawcett/Notepad
Fork: 106 Star: 880 (更新于 2024-11-27 06:40:17)
license: MIT
Language: Swift .
[iOS] A fully themeable markdown editor with live syntax highlighting.
最后发布版本: 0.3.0 ( 2019-04-06 00:29:18)
Usage
let notepad = Notepad(frame: view.bounds, themeFile: "one-dark")
view.addSubview(notepad)
Notepad is just like any other UITextView, but you need to use the convenience initializer in order to use the themes. To create a new theme, copy one of the existing themes and edit the JSON.
Check out the Xcode project for an example. For full documentation read the code.
Extending an Existing Text View with Notepad Features
If you cannot work with the Notepad
subclass directly for some reason, you can set up an existing UITextView
or NSTextView
on your own.
For iOS, you have to initialize all TextKit components yourself. Take the following as a blueprint where you can swap in custom objects:
class ViewController: UIViewController {
var textView: UITextView!
override func viewDidLoad() {
super.viewDidLoad()
let containerSize = CGSize(width: self.view.bounds.width, height: CGFloat.greatestFiniteMagnitude)
let container = NSTextContainer(size: containerSize)
container.widthTracksTextView = true
let layoutManager = NSLayoutManager()
layoutManager.addTextContainer(container)
let storage = Storage()
let theme = Theme("one-dark")
storage.theme = theme
storage.addLayoutManager(layoutManager)
let editor = UITextView(frame: self.view.bounds, textContainer: container)
editor.backgroundColor = theme.backgroundColor
editor.tintColor = theme.tintColor
editor.autoresizingMask = [.flexibleWidth, .flexibleHeight]
}
}
And for macOS:
class ViewController: NSViewController {
@IBOutlet var textView: NSTextView!
let storage = Storage()
override func viewDidLoad() {
super.viewDidLoad()
let theme = Theme("one-dark")
storage.theme = theme
textView.backgroundColor = theme.backgroundColor
textView.insertionPointColor = theme.tintColor
textView.layoutManager?.replaceTextStorage(storage)
}
}
Themes
Take a look at all of the themes and swatches when choosing the theme for your Notepad, or as inspiration for a new one.
You can find all of the raw themes in the themes folder, and the file names are case-sensitive.
Custom Regex
Using regex, you can match custom patterns in your Notepad editor by passing a regex
attribute in your theme. For example, one that highlights Twitter handles in a teal color:
"handle": {
"regex": "[@@][a-zA-Z0-9_]{1,20}",
"color": "#78ddd5"
}
Installation
Copy the source from the Notepad folder to your project, or add Notepad to your Podfile if you're using CocoaPods.
最近版本更新:(数据更新于 1970-01-01 00:00:00)
2019-04-06 00:29:18 0.3.0
2016-11-19 14:58:52 0.2.4
2016-11-18 05:40:27 0.2.2
2016-10-19 10:21:25 0.2.1
2016-10-18 11:17:46 0.2.0
2016-10-16 12:07:41 0.1.1
2016-10-16 05:33:49 0.1.0
主题(topics):
cocoapods, ios, markdown, notepad, regex, syntax-highlighter, theme, uitextview
ruddfawcett/Notepad同语言 Swift最近更新仓库
2024-12-21 13:48:53 argmaxinc/WhisperKit
2024-12-19 06:06:30 stripe/stripe-ios
2024-12-16 23:43:56 wordpress-mobile/WordPress-iOS
2024-12-04 20:33:05 Artificial-Pancreas/iAPS
2024-12-03 10:12:09 utmapp/UTM
2024-11-25 23:11:48 Alamofire/Alamofire