-1

Currently I have the following text inside a label located in a cell:

var textvalue: String? = nil

        switch indexPath.row {
        case 0:
            textvalue = "Person: \(`pow`.name)"
            break
        case 2:
            textvalue = "Place: \(`pow`.address)"
            break
        default:
            fatalError("Error")
        }

    cell.textLabel?.text = textvalue

        return cell
    }

How can only the text Person: and Place: be bolded? Instead of the entire text string?

John
  • 965
  • 8
  • 16
  • Does this answer your question? [Make part of a UILabel bold in Swift](https://stackoverflow.com/questions/36486761/make-part-of-a-uilabel-bold-in-swift) – chirag90 Feb 10 '20 at 12:59
  • Well in my case there are different kinds of bold text string, I just don’t understand how this can implemented for a case like mine – John Feb 10 '20 at 13:03
  • @KennethPans You need to have attributed string and then simply udpate label like -- label.attributed = "your attributedStr" – Vasucd Feb 10 '20 at 13:05
  • @KennethPans have a look at the answers on the link, you can create a function and just pass your text and return an attributed text. – chirag90 Feb 10 '20 at 13:15

1 Answers1

0

Do like below:

    var textvalue: String?

    switch indexPath.row {
    case 0:
       cell.textLabel?.attributedText =
       NSMutableAttributedString()
           .bold("Person: ")
           .normal(`pow`.name)
       break
    case 2:
       cell.textLabel?.attributedText =
       NSMutableAttributedString()
           .bold("Place: ")
           .normal(`pow`.address)
       break
    default:
       fatalError("Error")
    }

    return cell
}
Vladislav Markov
  • 587
  • 1
  • 5
  • 19
Daljeet
  • 1,573
  • 2
  • 20
  • 40