Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bulleted list in Swift - iOS

I need to add bulleted text to textView in iOS app. I am looking at this link and this one and following their ideas. This is my code:

let paragraph = NSMutableParagraphStyle()
paragraph.firstLineHeadIndent = 15
paragraph.headIndent = 15

attributes = [
    NSAttributedStringKey.paragraphStyle: paragraph
]

attributedString = NSAttributedString(string: "\u{2022} Some text some text some text some text some text some text", attributes: attributes)
finalText.append(attributedString)

What I need is to get the text indented with the start of the text above. Like it is in the picture:

enter image description here

What I get is the text indented with the starting point of the bullet.

enter image description here

like image 940
surToTheW Avatar asked Jul 18 '18 12:07

surToTheW


1 Answers

Remove paragraph.firstLineHeadIndent = 15 from code...

let paragraph = NSMutableParagraphStyle()
paragraph.headIndent = 15

attributes = [
    NSAttributedStringKey.paragraphStyle: paragraph
]

attributedString = NSAttributedString(string: "\u{2022} Some text some text some text some text some text some text", attributes: attributes)
finalText.append(attributedString)

Please refer my sample code and screenshot

let style = NSMutableParagraphStyle()
        style.alignment = .left
        style.headIndent = 20

        let title = NSMutableAttributedString(string: "\u{2022} I need to add bulleted text to textView in iOS app. I am looking at this link and this one and following their ideas. This is my code:", attributes: [NSAttributedStringKey.paragraphStyle: style,NSAttributedStringKey.foregroundColor:UIColor.blue])

        let titleStr = NSMutableAttributedString(string: "\n\n\u{2022} I need to add bulleted text to textView in iOS app. I am looking at this link and this one and following their ideas. This is my code:", attributes: [NSAttributedStringKey.paragraphStyle: style,NSAttributedStringKey.foregroundColor:UIColor.blue])
        title.append(titleStr)
        titleLabel.attributedText = title

enter image description here

like image 83
Mahendra Y Avatar answered Sep 27 '22 22:09

Mahendra Y