Make part of a UILabel bold in Swift

后端 未结 9 1974
面向向阳花
面向向阳花 2020-12-02 12:50

I have a UILabel I\'ve made programmatically as:

var label = UILabel()

I\'ve then declared some styling for the label, includi

9条回答
  •  长情又很酷
    2020-12-02 13:49

    Swift 4 alternative:

    let attrs = [NSAttributedStringKey.font : UIFont.boldSystemFont(ofSize: 14)]
    let attributedString = NSMutableAttributedString(string: "BOLD TEXT", attributes:attrs)
    let normalString = NSMutableAttributedString(string: "normal text")
    attributedString.append(normalString)
    myLabel.attributedText = attributedString
    

提交回复
热议问题