2

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

tzuer
  • 321
  • 4
  • 12

1 Answers1

0

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
Justin Garcia
  • 328
  • 1
  • 11
  • Thanks for the answer but need it in an UITextView so they can be edited like the notes app. Tried with your suggestion but still not the expected result. – tzuer Feb 26 '17 at 10:53
  • My example is in fact editable. Are you sure you need a UITextView? – Justin Garcia Feb 26 '17 at 18:55
  • Thanks – your answer did lead me to find out that the only way to achieve the bullet style like Apple/Evernote is to use Webview. But..I am basically creating a notes editor app. So I assume we will need to use textview? Also need to be able the ability to get text at selected range, detect tapped character/word and exclusion paths.. – tzuer Feb 26 '17 at 23:01
  • Ah. You can get selected text and detect tapped words with Javascript but currently there is no proper equivalent for exclusion paths. The CSS float property lets you wrap text around a rectangular region but not an arbitrary path. I think [CSS Shapes](https://drafts.csswg.org/css-shapes/) may let you do that but it’s not implemented in WebKit yet. – Justin Garcia Feb 27 '17 at 00:14