I have this function for adding a bullet to a textView
let bullet: String = " ● "
func setAttributedValueForBullets(bullet: String, positionWhereTheCursorIs: Int?) {
var textRange = selectedRange
let selectedText = NSMutableAttributedString(attributedString: attributedText)
if let line = positionWhereTheCursorIs {
textRange.location = line
}
selectedText.mutableString.replaceCharacters(in: textRange, with: bullet)
let paragraphStyle = createParagraphAttribute()
selectedText.addAttributes([NSParagraphStyleAttributeName: paragraphStyle], range: NSMakeRange(textRange.location, bullet.length))
self.attributedText = selectedText
self.selectedRange = textRange
}
and it works when inserting a bullet to a paragraph with just one line like this
but when I add it to a paragraph with more than one line this happen
I want it to look like in the first image, without that space in the bullet and the begining of text
I have also tried to use
selectedText.insert(bullet, at: textRange.location)
instead of
selectedText.addAttributes([NSParagraphStyleAttributeName: paragraphStyle], range: NSMakeRange(textRange.location, bullet.length))