[Solved] How to bold first word of array?


Try the following code

var userComment = ["Time these make me.jenny is ","I can't she did it.", "Hey! what a great play made by brad", "I can't she .", "Time like make is a badass", "I can't it.", "She is a mean chose to place","Time me a badass", "Wow! I am just like jenny.I would shit", "I can't did it."]


var attributeCommentArray:[NSAttributedString] = []

for comment in userComment
{
    if comment.contains(" ")
    {
        let firstWord = comment.components(separatedBy: " ").first ?? ""
        let myString:NSMutableAttributedString = NSMutableAttributedString.init(string: comment)

        myString.addAttribute(NSAttributedString.Key.font,
                                     value: UIFont(
                                        name: "HelveticaNeue-Bold",
                                        size: 18.0)!,
                                     range: NSRange(
                                        location:0,
                                        length:firstWord.count))


        attributeCommentArray.append(myString)
    }
    else
    {
        attributeCommentArray.append(NSAttributedString.init(string: comment))
    }
}

Create Attrinbuted String array and use that array in uitableview cell label

cellForRowMethod

lable.attributedText = attributeCommentArray[indexPath.row];

4

solved How to bold first word of array?