How do I make an attributed string using Swift?

前端 未结 28 2178
耶瑟儿~
耶瑟儿~ 2020-11-22 10:11

I am trying to make a simple Coffee Calculator. I need to display the amount of coffee in grams. The \"g\" symbol for grams needs to be attached to my UILabel that I am usin

28条回答
  •  日久生厌
    2020-11-22 10:59

    The attributes can be setting directly in swift 3...

        let attributes = NSAttributedString(string: "String", attributes: [NSFontAttributeName : UIFont(name: "AvenirNext-Medium", size: 30)!,
             NSForegroundColorAttributeName : UIColor .white,
             NSTextEffectAttributeName : NSTextEffectLetterpressStyle])
    

    Then use the variable in any class with attributes

提交回复
热议问题