How do I make an attributed string using Swift?

前端 未结 28 2457
耶瑟儿~
耶瑟儿~ 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:53

    For me above solutions didn't work when setting a specific color or property.

    This did work:

    let attributes = [
        NSFontAttributeName : UIFont(name: "Helvetica Neue", size: 12.0)!,
        NSUnderlineStyleAttributeName : 1,
        NSForegroundColorAttributeName : UIColor.darkGrayColor(),
        NSTextEffectAttributeName : NSTextEffectLetterpressStyle,
        NSStrokeWidthAttributeName : 3.0]
    
    var atriString = NSAttributedString(string: "My Attributed String", attributes: attributes)
    

提交回复
热议问题