Reputation: 351
I'm trying to replicate Apple's Notes unordered list (bullet) but can't seem to get it work.
I am currently using this string as attributed string which displays fine. "\u{2022}\texample bullet "
However, when you try to select the string, it selects the bullet and indentation too. Unlike Apple's notes, it does not select the bullet and indent?
Searched across stack overflow existing questions and also Apple's website. The closest I found is NSTextList which is not available for iOS. Any suggestions?
Update – Evernote, Microsoft One Note seems to be able to do this in their text editor too.
Appreciate any help in either Swift / Objective C
Upvotes: 4
Views: 1207
Reputation: 2168
I implemented a simple demo app https://github.com/DominikBucher12/TextKit2-Interactive-Lists explaining how to work with interactive numbered lists.
The main issue with Apple demo is that it actually doesn't explain how to interactively add and delete the list items. It seems the TextKit2 still has a lot of issues with layout, so you need to do a little of hacking inside textViewShouldChange method to get things working when adding new points...
Please take a look at the repository, hopefully you can get around the code. :)
Upvotes: 0
Reputation: 326
Would a WKWebView and the contentEditable property work for you? Try the following in a Playground:
import PlaygroundSupport
import WebKit
let webView = WKWebView(frame: CGRect(x: 0, y: 0, width: 320, height: 320))
let html = "<style>body { padding: 2em; font-size: 48pt }</style><body contentEditable=\"true\"><ul><li>Hello World</li></ul></body>"
webView.loadHTMLString(html, baseURL: nil)
PlaygroundPage.current.liveView = webView
Upvotes: -1