swiftnsattributedstringuialertcontrollernumbered-list

Swift Attributed Left Intended Numbered List


I am using below code to create a list of rules in an alert style UIAlertController

let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.alignment = NSTextAlignment.Left
let messageText = NSMutableAttributedString(
    string: "1. Do not bully or target other users.\n2. Do not post others' private information.\n3. Do not post useless or offensive content.\n4. Do not post others' copyrighted content.\n5. Downvote and Flag posts which violate these rules.\n6. If you violate these rules, your account may be suspended and/or your content removed.",
    attributes: [
        NSParagraphStyleAttributeName: paragraphStyle,
        NSFontAttributeName : UIFont(name: "Lato-Regular", size: 13.0)!,
        NSForegroundColorAttributeName : colorAccentWords
    ]
)

It gives me alert view as shown below: enter image description here

What I want is to make the numbered list left intended so that overflow text from each line will be left aligned. How can I achieve that?


Solution

  • Set the headIndent property of paragraphStyle to an appropriate value, for example

    paragraphStyle.headIndent = 13.0